模块解析在本机中失败

时间:2017-12-19 11:44:32

标签: reactjs react-native webpack react-native-web

Error

我想在网页上看到我的应用,那么我该做什么?我按照这个链接 https://github.com/simonqian/react-helloworld 但我没有得到答案?所以请提供一些解决问题的链接

在我使用npm start启动npm后,我遇到了这种类型的错误?如何解决这个问题?

这是我的web.config.js文件。我的配置文件将在根目录

'use strict';

const UglifyJSPlugin = require('uglifyjs-webpack-plugin');

module.exports = {
    entry: 'E:/react/webnative/main.js',

        output: {
         // path: 'E:/',
          filename: 'index.js'
        },

      devServer: {
        inline : false,
        port: 7777
      },
 resolve :{
   extensions : ['.js','.jsx']
 },
  module: {
    rules: [
      {
        test: /\.pug$/,
        use: [
          'pug-loader?self'
        ]
      },
      {
        test: /\.css$/,
        use: [
          'style-loader',
          'css-loader'
        ]
      }  
    ],
   loaders: [
          {
            test: /\.jsx?$/,           
            //exclude:/(node_modules|bower_components)/,
            exclude: /node_modules/,
            loader: 'babel-loader',
            query: {
              cacheDirectory : true,
              presets: ["es2015", "react"]
            }
          }
        ]
  },
  plugins: [
    new UglifyJSPlugin()
  ]
};

1 个答案:

答案 0 :(得分:0)

您的网络包配置应如下所示,以便阅读.jsx文件:

module.exports = {
  entry: './app/assets/frontend/myFile.jsx',
  output: {
    path: __dirname + '/app/assets/javascripts',
    filename: 'bundle.js'
  },
  resolve: {
    extensions: ['', '.js', '.jsx']
  },
  module: {
   loaders: [{
     test: /\.jsx?$/,
     loader: 'babel',
     exclude: /node_modules/,
     query: {
       cacheDirectory: true,
       presets: ['react', 'es2015']
     }
   }]
 }
}

或者只是不要使用jsx。希望这有帮助!