简体   繁体   English

安装webpack和babel后,npm开始不工作

[英]npm start not working after installation of webpack and babel

I have created an app in react-redux. 我在react-redux中创建了一个应用程序。 After that I have installed babel and webpack using below link. 之后我使用下面的链接安装了babel和webpack。

https://medium.com/@siddharthac6/getting-started-with-react-js-using-webpack-and-babel-66549f8fbcb8 https://medium.com/@siddharthac6/getting-started-with-react-js-using-webpack-and-babel-66549f8fbcb8

Below is my webpack.config.js file: 下面是我的webpack.config.js文件:

const path = require('path');
const HWP = require('html-webpack-plugin');

module.exports = {
   entry: path.join(__dirname, '/src/index.js'),
   output: {
       filename: 'build.js',
       //path: path.join(__dirname, '/dist')},
       path: path.resolve(__dirname, 'build'),
   },
   module:{
       rules:[{
          test: /\.js$/,
          exclude: /node_modules/,
          loader: 'babel-loader'
       }]
   },
   plugins:[
       new HWP(
          {template: path.join(__dirname,'/src/index.html')}
       )
   ]
}

I'm getting below error when I run the "npm start" 当我运行“npm start”时,我遇到了以下错误

> my-app@0.1.0 start /var/www/html/SFL
> webpack-dev-server — mode development — open — hot

✖ 「wds」: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration.entry should be one of these:
   function | object { <key>: non-empty string | [non-empty string] } | non-empty string | [non-empty string]
   -> The entry point(s) of the compilation.
   Details:
    * configuration.entry should be an instance of function
      -> A Function returning an entry object, an entry string, an entry array or a promise to these things.
    * configuration.entry['main'] should be a string.
      -> The string is resolved to a module which is loaded upon startup.
    * configuration.entry['main'] should not contain the item '—' twice.
    * configuration.entry should be a string.
      -> An entry point without name. The string is resolved to a module which is loaded upon startup.
    * configuration.entry should be an array:
      [non-empty string]
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! my-app@0.1.0 start: `webpack-dev-server — mode development — open — hot`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the my-app@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

I'm trying to solve above error. 我正试图解决上面的错误。 Is there any other way to solve this error? 还有其他方法可以解决这个错误吗?

try this.. revert your changes and run npm run eject 试试这个..还原您的更改并运行npm run eject

this will enable webpack into your project 这将使webpack进入您的项目

Try this delete you node_modules && your package-lock.json 试试这个删除你node_modules &&你的package-lock.json

and run npm i again. 并再次运行npm i。

let me know if it works. 让我知道它是否有效。

尝试将您的entry更改为此(取自create-react-app ):

entry: [ require.resolve('webpack-dev-server/client') + '?/', require.resolve('webpack/hot/dev-server'), path.join(__dirname, '/src/index.js') ]

Your folder structure should look like this 您的文件夹结构应如下所示

├── webpack.config.js
├── src
│   ├── index.js

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

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