Webpack - extract-text-webpack-plugin 找不到模块

19

webpack.config.js

var ExtractTextPlugin = require("extract-text-webpack-plugin");

如果我只是实现这个插件,我会立即收到这个错误:

module.js:339
    throw err;
    ^

Error: Cannot find module 'webpack/lib/ConcatSource'
    at Function.Module._resolveFilename (module.js:337:15)
    at Function.Module._load (module.js:287:25)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at Object.<anonymous> (/Users/lucamormile/Documents/Lavori/Webapps/React/webpack_test/node_modules/extract-text-webpack-plugin/index.js:5:20)
    at Module._compile (module.js:425:26)
    at Object.Module._extensions..js (module.js:432:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Module.require (module.js:366:17)

我忘了什么?


2
npm install extract-text-webpack-plugin - J. Mark Stevens
已经安装好了... - Luca Mormile
1
这个Github仓库上的bug似乎很相关。 - doug65536
1
来自未来的消息,值得考虑:npm WARN deprecated extract-text-webpack-plugin@3.0.2: Please use https://github.com/webpack-contrib/mini-css-extract-plugin。 - B--rian
5个回答

20

您的项目中是否有webpack模块?
如果没有,请本地安装(而非全局安装):

$ npm install webpack [--save-dev]

extract-text-webpack-plugin 需要作为对等依赖项 webpack,但是 npm 3 不会自动安装对等依赖项。


对我来说,这个方法适用于使用yarn安装extract-text-webpack-plugin。 - Allahbaksh Asadullah

18

2
我通过使用来解决了它。
npm install extract-text-webpack-plugin --save-dev 

1

这对我有用。在尝试这个之前,我也尝试了其他修复方法。由于某种原因,其他方法都没有起作用。 - mikey

-3

运行 npm i node-sass 可能会解决你的问题。


3
简要说明为什么会奏效是有帮助的,这样未来的读者更有可能尝试。 - doug65536

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接