为了账号安全,请及时绑定邮箱和手机立即绑定

npm run dev报错,所有依赖和老师一样就是不行

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

const isDev = process.env.NODE_ENV === 'development';

const config = {
    target: 'web', //跑在浏览器上,所以编译目标是web
    entry: path.join(__dirname, 'src/index.js'),
    output: {
        filename: "bundle.js",
        path: path.join(__dirname, 'dist')
    },
    module: {
        rules: [
            {
                test: /\.vue$/,
                loader: 'vue-loader'
            },
            {
                test: /\.css$/,
                use: [
                    'style-loader',
                    'css-loader'
                ]
            },
            {
                test:/\.styl/,
                use: [
                    'style-loader',
                    'css-loader',
                    'stylus-loader'
                ]
            },
            {
                test: /\.(gif|jpg|jpeg|png|svg)$/,
                use: [
                    {
                        loader:'url-loader',
                        options: {
                            limit: 1024,
                            name: '[name]star.[ext]'
                        }
                    }
                ]
            }
        ]
    },
    plugins: [
        //判断环境,vue框架一定要用
        new webpack.DefinePlugin({
            'process.env': {
                NODE_ENV: isDev ? '"development"' : '"production"'
            }
        }),
        new HTMLPlugin()
    ]
};

if(isDev) {
    config.devServer = {
        port: 8000,
        host: '0.0.0.0',
        overlay: {
            errors: true,
        },
        // hot: true
    }
}

module.exports = config



报错问题


D:\练手\todo>npm run dev

> todo@1.0.0 dev D:\练手\todo
> cross-env NODE_ENV=development webpack-dev-server webpack --config webpack.config.js

Project is running at http://0.0.0.0:8000/
webpack output is served from /
No parser and no filepath given, using 'babylon' the parser now but this will throw an error in the future. Please specify a parser or a filepath so one can be inferred.
Hash: 032d8f597acc3f799edc
Version: webpack 3.10.0
Time: 4325ms
     Asset       Size  Chunks                    Chunk Names
 1star.jpg    51.1 kB          [emitted]
 bundle.js    4.44 MB       0  [emitted]  [big]  main
index.html  182 bytes          [emitted]
  [53] (webpack)/lib/ExternalsPlugin.js 529 bytes {0} [built]
  [56] ./node_modules/url/url.js 23.3 kB {0} [built]
 [349] multi (webpack)-dev-server/client?http://0.0.0.0:8000 ./src/index.js webpack 52 bytes {0} [built]
 [350] (webpack)-dev-server/client?http://0.0.0.0:8000 7.95 kB {0} [built]
 [367] ./src/index.js 301 bytes {0} [built]
 [385] (webpack)/lib/webpack.js 5.82 kB {0} [built]
 [803] (webpack)/lib/ContextExclusionPlugin.js 401 bytes {0} [built]
 [835] (webpack)/lib/NamedChunksPlugin.js 653 bytes {0} [built]
 [836] (webpack)/lib/HashedModuleIdsPlugin.js 1.15 kB {0} [built]
 [837] (webpack)/lib/optimize/AggressiveMergingPlugin.js 3.17 kB {0} [built]
 [838] (webpack)/lib/optimize/AggressiveSplittingPlugin.js 7.23 kB {0} [built]
 [839] (webpack)/lib/optimize/CommonsChunkPlugin.js 14.8 kB {0} [built]
 [840] (webpack)/lib/optimize/ChunkModuleIdRangePlugin.js 1.47 kB {0} [built]
 [841] (webpack)/lib/optimize/DedupePlugin.js 396 bytes {0} [built]
 [842] (webpack)/lib/optimize/LimitChunkCountPlugin.js 1.99 kB {0} [built]
    + 891 hidden modules

WARNING in ./node_modules/uglify-js/tools/node.js
24:11-32 Critical dependency: the request of a dependency is an expression
 @ ./node_modules/uglify-js/tools/node.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/index.js
 @ (webpack)/lib/optimize/UglifyJsPlugin.js
 @ (webpack)/lib/webpack.js
 @ multi (webpack)-dev-server/client?http://0.0.0.0:8000 ./src/index.js webpack

WARNING in ./node_modules/loader-runner/lib/loadLoader.js
3:2-28 Critical dependency: the request of a dependency is an expression
 @ ./node_modules/loader-runner/lib/loadLoader.js
 @ ./node_modules/loader-runner/lib/LoaderRunner.js
 @ (webpack)/lib/NormalModule.js
 @ (webpack)/lib/AutomaticPrefetchPlugin.js
 @ (webpack)/lib/webpack.js
 @ multi (webpack)-dev-server/client?http://0.0.0.0:8000 ./src/index.js webpack

WARNING in ./node_modules/chokidar/lib/fsevents-handler.js
Module not found: Error: Can't resolve 'fsevents' in 'D:\练手\todo\node_modules\chokidar\lib'
 @ ./node_modules/chokidar/lib/fsevents-handler.js 7:17-36
 @ ./node_modules/chokidar/index.js
 @ ./node_modules/watchpack/lib/DirectoryWatcher.js
 @ ./node_modules/watchpack/lib/watcherManager.js
 @ ./node_modules/watchpack/lib/watchpack.js
 @ (webpack)/lib/node/NodeWatchFileSystem.js
 @ (webpack)/lib/node/NodeEnvironmentPlugin.js
 @ (webpack)/lib/webpack.js
 @ multi (webpack)-dev-server/client?http://0.0.0.0:8000 ./src/index.js webpack

ERROR in ./node_modules/chokidar/index.js
Module not found: Error: Can't resolve 'fs' in 'D:\练手\todo\node_modules\chokidar'
 @ ./node_modules/chokidar/index.js 3:9-22
 @ ./node_modules/watchpack/lib/DirectoryWatcher.js
 @ ./node_modules/watchpack/lib/watcherManager.js
 @ ./node_modules/watchpack/lib/watchpack.js
 @ (webpack)/lib/node/NodeWatchFileSystem.js
 @ (webpack)/lib/node/NodeEnvironmentPlugin.js
 @ (webpack)/lib/webpack.js
 @ multi (webpack)-dev-server/client?http://0.0.0.0:8000 ./src/index.js webpack

ERROR in ./node_modules/chokidar/lib/fsevents-handler.js
Module not found: Error: Can't resolve 'fs' in 'D:\练手\todo\node_modules\chokidar\lib'
 @ ./node_modules/chokidar/lib/fsevents-handler.js 3:9-22
 @ ./node_modules/chokidar/index.js
 @ ./node_modules/watchpack/lib/DirectoryWatcher.js
 @ ./node_modules/watchpack/lib/watcherManager.js
 @ ./node_modules/watchpack/lib/watchpack.js
 @ (webpack)/lib/node/NodeWatchFileSystem.js
 @ (webpack)/lib/node/NodeEnvironmentPlugin.js
 @ (webpack)/lib/webpack.js
 @ multi (webpack)-dev-server/client?http://0.0.0.0:8000 ./src/index.js webpack

ERROR in ./node_modules/chokidar/lib/nodefs-handler.js
Module not found: Error: Can't resolve 'fs' in 'D:\练手\todo\node_modules\chokidar\lib'
 @ ./node_modules/chokidar/lib/nodefs-handler.js 3:9-22
 @ ./node_modules/chokidar/index.js
 @ ./node_modules/watchpack/lib/DirectoryWatcher.js
 @ ./node_modules/watchpack/lib/watcherManager.js
 @ ./node_modules/watchpack/lib/watchpack.js
 @ (webpack)/lib/node/NodeWatchFileSystem.js
 @ (webpack)/lib/node/NodeEnvironmentPlugin.js
 @ (webpack)/lib/webpack.js
 @ multi (webpack)-dev-server/client?http://0.0.0.0:8000 ./src/index.js webpack

ERROR in ./node_modules/graceful-fs/graceful-fs.js
Module not found: Error: Can't resolve 'fs' in 'D:\练手\todo\node_modules\graceful-fs'
 @ ./node_modules/graceful-fs/graceful-fs.js 1:9-22
 @ ./node_modules/enhanced-resolve/lib/NodeJsInputFileSystem.js
 @ (webpack)/lib/node/NodeEnvironmentPlugin.js
 @ (webpack)/lib/webpack.js
 @ multi (webpack)-dev-server/client?http://0.0.0.0:8000 ./src/index.js webpack

ERROR in ./node_modules/graceful-fs/fs.js
Module not found: Error: Can't resolve 'fs' in 'D:\练手\todo\node_modules\graceful-fs'
 @ ./node_modules/graceful-fs/fs.js 3:9-22
 @ ./node_modules/graceful-fs/graceful-fs.js
 @ ./node_modules/enhanced-resolve/lib/NodeJsInputFileSystem.js
 @ (webpack)/lib/node/NodeEnvironmentPlugin.js
 @ (webpack)/lib/webpack.js
 @ multi (webpack)-dev-server/client?http://0.0.0.0:8000 ./src/index.js webpack

ERROR in ./node_modules/loader-runner/lib/LoaderRunner.js
Module not found: Error: Can't resolve 'fs' in 'D:\练手\todo\node_modules\loader-runner\lib'
 @ ./node_modules/loader-runner/lib/LoaderRunner.js 5:9-22
 @ (webpack)/lib/NormalModule.js
 @ (webpack)/lib/AutomaticPrefetchPlugin.js
 @ (webpack)/lib/webpack.js
 @ multi (webpack)-dev-server/client?http://0.0.0.0:8000 ./src/index.js webpack

ERROR in ./node_modules/mkdirp/index.js
Module not found: Error: Can't resolve 'fs' in 'D:\练手\todo\node_modules\mkdirp'
 @ ./node_modules/mkdirp/index.js 2:9-22
 @ (webpack)/lib/node/NodeOutputFileSystem.js
 @ (webpack)/lib/node/NodeEnvironmentPlugin.js
 @ (webpack)/lib/webpack.js
 @ multi (webpack)-dev-server/client?http://0.0.0.0:8000 ./src/index.js webpack

ERROR in ./node_modules/snapdragon/lib/source-maps.js
Module not found: Error: Can't resolve 'fs' in 'D:\练手\todo\node_modules\snapdragon\lib'
 @ ./node_modules/snapdragon/lib/source-maps.js 3:9-22
 @ ./node_modules/snapdragon/lib/compiler.js
 @ ./node_modules/snapdragon/index.js
 @ ./node_modules/braces/lib/braces.js
 @ ./node_modules/braces/index.js
 @ ./node_modules/chokidar/index.js
 @ ./node_modules/watchpack/lib/DirectoryWatcher.js
 @ ./node_modules/watchpack/lib/watcherManager.js
 @ ./node_modules/watchpack/lib/watchpack.js
 @ (webpack)/lib/node/NodeWatchFileSystem.js
 @ (webpack)/lib/node/NodeEnvironmentPlugin.js
 @ (webpack)/lib/webpack.js
 @ multi (webpack)-dev-server/client?http://0.0.0.0:8000 ./src/index.js webpack

ERROR in ./node_modules/uglify-js/tools/node.js
Module not found: Error: Can't resolve 'fs' in 'D:\练手\todo\node_modules\uglify-js\tools'
 @ ./node_modules/uglify-js/tools/node.js 8:9-22
 @ ./node_modules/uglifyjs-webpack-plugin/dist/index.js
 @ (webpack)/lib/optimize/UglifyJsPlugin.js
 @ (webpack)/lib/webpack.js
 @ multi (webpack)-dev-server/client?http://0.0.0.0:8000 ./src/index.js webpack

ERROR in (webpack)/lib/node/NodeMainTemplateAsync.runtime.js
Module not found: Error: Can't resolve 'fs' in 'D:\练手\todo\node_modules\webpack\lib\node'
 @ (webpack)/lib/node/NodeMainTemplateAsync.runtime.js 9:2-15 25:3-16
 @ (webpack)/lib/node/NodeMainTemplatePlugin.js
 @ (webpack)/lib/node/NodeTemplatePlugin.js
 @ (webpack)/lib/WebpackOptionsApply.js
 @ (webpack)/lib/webpack.js
 @ multi (webpack)-dev-server/client?http://0.0.0.0:8000 ./src/index.js webpack

ERROR in (webpack)/lib/node/NodeOutputFileSystem.js
Module not found: Error: Can't resolve 'fs' in 'D:\练手\todo\node_modules\webpack\lib\node'
 @ (webpack)/lib/node/NodeOutputFileSystem.js 7:11-24
 @ (webpack)/lib/node/NodeEnvironmentPlugin.js
 @ (webpack)/lib/webpack.js
 @ multi (webpack)-dev-server/client?http://0.0.0.0:8000 ./src/index.js webpack

ERROR in (webpack)/lib/NormalModule.js
Module not found: Error: Can't resolve 'module' in 'D:\练手\todo\node_modules\webpack\lib'
 @ (webpack)/lib/NormalModule.js 8:21-38
 @ (webpack)/lib/AutomaticPrefetchPlugin.js
 @ (webpack)/lib/webpack.js
 @ multi (webpack)-dev-server/client?http://0.0.0.0:8000 ./src/index.js webpack
Child html-webpack-plugin for "index.html":
     1 asset
       [0] ./node_modules/html-webpack-plugin/lib/loader.js!./node_modules/html-webpack-plugin/default_index.ejs 376 bytes {0} [built]
       [1] ./node_modules/lodash/lodash.js 540 kB {0} [built]
       [2] (webpack)/buildin/global.js 509 bytes {0} [built]
       [3] (webpack)/buildin/module.js 517 bytes {0} [built]
webpack: Failed to compile.

正在回答

1 回答

倒数那里

host: '0.0.0.0',

这里的0.0.0.0改为127.0.0.1或者 localhost

0 回复 有任何疑惑可以回复我~
#1

感性理性 提问者

还是报一样的错欸, 浏览器可以浏览但蒙层有如下报错 Failed to compile. ./node_modules/chokidar/index.js Module not found: Error: Can't resolve 'fs' in 'D:\练手\todo ..... /node/NodeEnvironmentPlugin.js @ (webpack)/lib/webpack.js @ multi (webpack)-dev-server/client?http://localhost:8000 ./src/index.js webpack
2018-10-18 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
Vue+Webpack打造todo应用
  • 参与学习       84606    人
  • 解答问题       787    个

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

进入课程

npm run dev报错,所有依赖和老师一样就是不行

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信