简体   繁体   English

Webpack没有构建css文件

[英]Webpack not building css file

So I was following the tutorial on http://webpack.github.io/docs/tutorials/getting-started/ and I was stuck on the css style loader step. 所以我按照http://webpack.github.io/docs/tutorials/getting-started/上的教程进行操作,我被困在css样式加载器步骤中。 Here is my entry.js: 这是我的entry.js:

require("!style!css!./style.css");
document.write(require("./content.js"))

this is content.js: 这是content.js:

module.exports = "It works from content.js";

this is style.css: 这是style.css:

body{
    background: yellow;
}

After this, I am running this command: 在此之后,我正在运行此命令:

webpack ./entry.js bundle.js webpack ./entry.js bundle.js

I am getting this error: 我收到此错误:

Version: webpack 1.13.0 Time: 866ms Asset Size Chunks Chunk Names bundle.js 10.1 kB 0 [emitted] main [0] ./entry.js 115 bytes {0} [built] [4] ./content.js 45 bytes {0} [built] + 3 hidden modules 版本:webpack 1.13.0时间:866ms资产大小块块名称bundle.js 10.1 kB 0 [emit] main [0] ./entry.js 115字节{0} [built] [4] ./content.js 45 bytes {0} [built] + 3个隐藏模块

ERROR in ./~/css-loader!./style.css Module build failed: ReferenceError: Promise is not defined at LazyResult.async (/var/www/html/webpack/node_modules/css-loader/node_modules/postcss/lib/lazy-result.js:157:31) at LazyResult.then (/var/www/html/webpack/node_modules/css-loader/node_modules/postcss/lib/lazy-result.js:79:21) at processCss (/var/www/html/webpack/node_modules/css-loader/lib/processCss.js:198:5) at Object.module.exports (/var/www/html/webpack/node_modules/css-loader/lib/loader.js:24:2) @ ./~/style-loader!./~/css-loader!./style.css 4:14-73 ./~/css-loader!。/ style.css中的错误模块构建失败:ReferenceError:未在LazyResult.async中定义Promise(/ var / www / html / webpack / node_modules / css-loader / node_modules / postcss / lib /lazy-result.js:157:31)在processCss上的LazyResult.then(/var/www/html/webpack/node_modules/css-loader/node_modules/postcss/lib/lazy-result.js:79:21) /var/www/html/webpack/node_modules/css-loader/lib/processCss.js:198:5)在Object.module.exports(/ var / www / html / webpack / node_modules / css-loader / lib / loader) .js:24:2)@ ./~/style-loader!./~/css-loader!。/ style.css 4:14-73

How to fix this? 如何解决这个问题?

As mentioned in the comments, your version of Node is very old (in fact, support for v0.10.x is being dropped in October). 正如评论中所提到的,您的Node版本非常陈旧(事实上,10月份将删除对v0.10.x的支持)。 Support for native JavaScript Promise objects wasn't added until Node v4, and as suggested by the error message you posted, css-loader makes use of these behind the scenes. 直到Node v4才添加对原生JavaScript Promise对象的支持,并且根据您发布的错误消息的建议, css-loader在后台使用这些对象。

So the only real solution to this issue is to update Node. 所以这个问题的唯一真正解决方案是更新Node。 There are two versions that you can choose from at the moment; 目前有两种版本可供您选择; v4 is the most stable but lacks some newer features, whereas v6 has the latest features but might be more buggy/less well supported. v4是最稳定的,但缺少一些较新的功能,而v6具有最新的功能,但可能更多的错误/不太支持。

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

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