在npm run dev的时候进行报错

来源:2-3 webpack-dev-server的配置和使用

笔墨微凉

2020-05-02 09:45

wazehaodeMBP:VUE-Test wazehao$ npm run dev


> vue-test@1.0.0 dev /Users/wazehao/code/VsCode/VUE-Test

> cross-env NODE_ENV=development webpack-dev-server --config webpack.config.js


/Users/wazehao/code/VsCode/VUE-Test/webpack.config.js:58

        new webpack.DefinPlugin({

        ^


TypeError: webpack.DefinPlugin is not a constructor

    at Object.<anonymous> (/Users/wazehao/code/VsCode/VUE-Test/webpack.config.js:58:9)

    at Module._compile (internal/modules/cjs/loader.js:1156:30)

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)

    at Module.load (internal/modules/cjs/loader.js:1000:32)

    at Function.Module._load (internal/modules/cjs/loader.js:899:14)

    at Module.require (internal/modules/cjs/loader.js:1042:19)

    at require (internal/modules/cjs/helpers.js:77:18)

    at WEBPACK_OPTIONS (/Users/wazehao/code/VsCode/VUE-Test/node_modules/webpack-cli/bin/utils/convert-argv.js:114:13)

    at requireConfig (/Users/wazehao/code/VsCode/VUE-Test/node_modules/webpack-cli/bin/utils/convert-argv.js:116:6)

    at /Users/wazehao/code/VsCode/VUE-Test/node_modules/webpack-cli/bin/utils/convert-argv.js:123:17

npm ERR! code ELIFECYCLE

npm ERR! errno 1

npm ERR! vue-test@1.0.0 dev: `cross-env NODE_ENV=development webpack-dev-server --config webpack.config.js`

npm ERR! Exit status 1

npm ERR! 

npm ERR! Failed at the vue-test@1.0.0 dev script.

npm ERR! This is probably not a problem with npm. There is likely additional logging output above.


npm ERR! A complete log of this run can be found in:

npm ERR!     /Users/wazehao/.npm/_logs/2020-05-02T01_43_46_817Z-debug.log


写回答 关注

5回答

  • 游客305
    2021-02-23 17:20:00

    我也报同样的错,和视频里代码一模一样,不知道怎么搞了?

    慕神2292... 回复qq_小丁_...

    哪里的大写改成小写啊

    2022-04-14 17:47:16

    共 2 条回复 >

  • Ricard_Q
    2020-11-04 10:37:14

    new webpack.DefinPlugin  => new webpack.DefinePlugin 少写个E


  • 向北丶
    2020-05-26 22:10:01

    你是不是 只注意了 plugins里的配置,那你在页首 引入了 webpack 了吗? 需要提供代码,才能知道你具体的问题。

  • 慕神2229659
    2020-05-14 20:31:09

    我也是同样的问题 webpack 也引入了 和老师的代码一样

    游客305

    我也是

    2021-02-23 17:20:56

    共 1 条回复 >

  • tencyooo
    2020-05-05 10:07:05


    根据你的报错来看,是webpack相关设置出了问题,可能是代码写错了。
    webpack.config.js里面-plugins里面需要写以下:

    new webpack.DefinePlugin({

                'process.env': {

                    NODE_ENV: isDev ? '"development"' : '"production"'

                }

            }),


    同时最上面需要引入webpack 

    const webpack = require('webpack')


Vue+Webpack打造todo应用

用前端最热门框架Vue+最火打包工具Webpack打造todo应用

84606 学习 · 787 问题

查看课程

相似问题