简体   繁体   English

npm启动webpack问题?

[英]npm start webpack issue?

I got mini app in react and trying to start it with npm start - package.json - "scripts": { "start": "node server.js" 我在响应中使用了微型应用程序,并尝试使用npm start-package.json-“ scripts”:{“ start”:“ node server.js”来启动它

All works fine in windows but when trying to start this on Ubuntu console throws an error 在Windows中一切正常,但是当尝试在Ubuntu控制台上启动时抛出错误

/var/www/react_pwa/node_modules/webpack/lib/RuleSet.js:143 /var/www/react_pwa/node_modules/webpack/lib/RuleSet.js:143
throw new Error("options/query cannot be used with loaders"); 抛出新的错误(“选项/查询不能与加载程序一起使用”);

I've updated node.js and npm so I thik this might be webpack configuration issue. 我已经更新了node.js和npm,所以我认为这可能是webpack配置问题。 The file looks like this now 该文件现在看起来像这样

var path = require('path');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  devtool: 'eval',
  entry: [
    'react-hot-loader/patch',
    'webpack-dev-server/client?http://localhost:3000',
    'webpack/hot/only-dev-server',
    './src/index'
  ],
  output: {
    path: path.join(__dirname, 'dist'),
    filename: 'bundle.js',
    publicPath: '/'
  },
  plugins: [
    new webpack.HotModuleReplacementPlugin(),
      new HtmlWebpackPlugin({
      template: 'index.html'
    })
  ],
  module: {
    loaders: [{
      test: /\.js$/,
      loaders: ['babel'],
      include: path.join(__dirname, 'src'),
      query: {
        "presets": [
          "es2015",
          "stage-0",
          "react"
        ],
        "plugins": [
          "react-hot-loader/babel"
        ]
      }
    },
    {
      test: /\.css/,
      loaders: ["style", "css"]
    }]
  }
};

Any ideas? 有任何想法吗? Thanks. 谢谢。

Change loaders: ['babel'] to loader: 'babel' and it should work. loaders: ['babel']更改为loader: 'babel' ,它应该可以工作。

I don't think you can use query with multiple "loaders" because it doesn't know what query to attach to which loader. 我认为您无法将查询与多个“加载程序”一起使用,因为它不知道将哪个查询附加到哪个加载程序。

You are probably missing a dependency in your package.json . 您可能在package.json缺少依赖项。

Have you installed react-hot-loader , css-loader , style-loader , babel-loader , babel-core , babel-preset-es2015 , babel-preset-react , babel-preset-stage-0 ? 您是否安装了react-hot-loadercss-loaderstyle-loaderbabel-loaderbabel-corebabel-preset-es2015babel-preset-reactbabel-preset-stage-0吗?

Try running this command to make sure: 尝试运行此命令以确保:

npm install --save-dev react-hot-loader css-loader style-loader babel-loader babel-core babel-preset-es2015 babel-preset-react babel-preset-stage-0

Another thing you can do is ls node_modules in your windows setup and make sure all dependencies are in your package.json so you install them on npm install . 您可以做的另一件事是在Windows安装ls node_modules中使用ls node_modules并确保所有依赖项都在package.json因此可以在npm install上安装它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM