linux - react 项目设置 - npm 运行 webpack 问题

标签 linux reactjs npm webpack installation

我正在关注 http://ccoenraets.github.io/es6-tutorial-react/setup/用于 react 项目设置。最后部分,运行后出现此错误

npm run webpack

我遇到的错误 -

npm run webpack

> project-newborn@1.0.0 webpack /home/rishi/Desktop/project-newborn
> webpack

Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration.module has an unknown property 'loaders'. These properties are valid:
   object { exprContextCritical?, exprContextRecursive?, exprContextRegExp?, exprContextRequest?, noParse?, rules?, defaultRules?, unknownContextCritical?, unknownContextRecursive?, unknownContextRegExp?, unknownContextRequest?, unsafeCache?, wrappedContextCritical?, wrappedContextRecursive?, wrappedContextRegExp?, strictExportPresence?, strictThisContextOnImports? }
   -> Options affecting the normal modules (`NormalModuleFactory`).

npm ERR! Linux 4.15.0-34-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "run" "webpack"
npm ERR! node v8.10.0
npm ERR! npm  v3.5.2
npm ERR! code ELIFECYCLE
npm ERR! project-newborn@1.0.0 webpack: `webpack`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the project-newborn@1.0.0 webpack script 'webpack'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the project-newborn package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     webpack
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs project-newborn
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls project-newborn
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/rishi/Desktop/project-newborn/npm-debug.log

最佳答案

使用 Webpack 4 时您必须使用 rules 而不是 loaders 并且最好使用 use 而不是 loader

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

 module.exports = {
     entry: './js/app.js',
     output: {
         path: path.resolve(__dirname, 'build'),
         filename: 'app.bundle.js'
     },
     module: {
         rules: [
             {
                 test: /\.js$/,
                 use: [
                     {
                         loader: 'babel-loader',
                         options: {
                             presets: ['es2015', 'react'],
                         },
                     },
                 ],
             }
         ]
     },
     stats: {
         colors: true
     },
     devtool: 'source-map'
 };

关于linux - react 项目设置 - npm 运行 webpack 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52268352/

相关文章:

ruby - 生成源映射时出错 - grunt 和 sass 配置

node.js - 找不到模块 '.tmp/Rx.min.js'

linux - 在远程机器上执行多个命令

c++ - 在哪里可以找到 arm-linux-gnueabihf-ld 的联机帮助页,更不用说编写良好的联机帮助页了,其中包括 -rpath 和 -rpath-link?

javascript - 将 HTML 插入用户字符串并在 React 中渲染(并避免 XSS 威胁)

javascript - Redux 组件不会因商店更改而更新

linux - 混帐/Linux : What is a good strategy for maintaining a Linux kernel with patches from multiple Git repositories?

用于更改文件权限以反射(reflect)以下权限集的 linux 命令

javascript - react this.props.title 为空!!为什么?

javascript - 让 JS 库对 Node 和 Window 感到满意