webpack打包出现react-dom相关错误

login.js代码

import React from 'react';
import ReactDOM from 'react-dom';

function tick() {
  const element = (
    <div>
      <h1>Hello, world!</h1>
      <h2>It is {new Date().toLocaleTimeString()}.</h2>
    </div>
  );
  ReactDOM.render(
    element,
    document.getElementById('root')
  );
}

webpack.config.js代码

const webpack = require('webpack');
const path=require('path');

module.exports=(env)=>{
    return {
        entry:{
            main:'./login.js',
            vendor1:'React',
            vendor2:'ReactDOM'
        },

        output:{
            filename:'[name].bundle.js',
            path:path.resolve(__dirname,'dist')
        },
         module: {
            rules: [
              {
                test: /\.(js|jsx)$/,
                loader: 'babel-loader'
              }
            ]
         },
        plugins:[
            new webpack.optimize.CommonsChunkPlugin({
                name:'manifest'
            }),

        /*    new webpack.optimize.CommonsChunkPlugin({
                name:'vendor1',
                minChunks:(module)=>{
                    return module.context&&module.context.indexOf('node_modules')!==-1;
                }
            }),

            new webpack.optimize.CommonsChunkPlugin({
                name:'vendor2',
                minChunks:(module)=>{
                    return module.context&&module.context.indexOf('node_modules')!==-1;
                }
            })*/
        ]
    }
}
setInterval(tick, 1000);

控制台错误

WARNING in D:/node/likeread/~/React/lib/ReactPropTypesSecret.js
There are multiple modules with names that only differ in casing.
This can lead to unexpected behavior when compiling on a filesystem with other case-semantic.
Use equal casing. Compare these module identifiers:
* D:\node\likeread\node_modules\babel-loader\lib\index.js!D:\node\likeread\node_modules\React\lib\ReactPropTypesSecret.js
    Used by 1 module(s), i. e.
    D:\node\likeread\node_modules\babel-loader\lib\index.js!D:\node\likeread\node_modules\React\lib\checkReactTypeSpec.js
* D:\node\likeread\node_modules\babel-loader\lib\index.js!D:\node\likeread\node_modules\react\lib\ReactPropTypesSecret.js
    Used by 1 module(s), i. e.
    D:\node\likeread\node_modules\babel-loader\lib\index.js!D:\node\likeread\node_modules\react\lib\checkReactTypeSpec.js

ERROR in Entry module not found: Error: Can't resolve 'ReactDOM' in 'D:\node\likeread\public\javascripts'
阅读 4.8k
1 个回答

你把ReactDOM.render()写在tick方法中是什么意思?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题