webpack:在MacOS上很好,在linux上加载程序错误

webpack: fine on MacOS, loader errors on linux

本文关键字:加载 错误 程序 linux 很好 MacOS webpack      更新时间:2023-09-26

我遇到了一些webpack/raw-loader/sass同步加载程序问题。在我的本地机器上,一切都很顺利。然而,在我的linux CI服务器上,webpack失败了。

有人能告诉我如何开始诊断发生了什么吗?我不太确定从哪里开始。

以下是linux上的webpack输出:

Hash: 314a28b414704badd07b
Version: webpack 1.4.15
Time: 7350ms
   Asset     Size  Chunks             Chunk Names
 main.js  1648360       0  [emitted]  main
main.css   138069       0  [emitted]  main
    + 595 hidden modules
ERROR in ./~/raw-loader!./~/autoprefixer-loader
!./node_loaders/sass-sync-loader.js?sync&outputStyle=compact&
includePaths[]=/home/u65/src/repo/desktop-prototype/.generated/design-assets&
includePaths[]=/home/u65/src/repo/desktop-prototype/.generated/design-properties&
includePaths[]=/home/u65/src/repo/desktop-prototype/app!./app/index.scss
Module build failed: 
 @ ./app/index.scss 4:14-564
<SNIP>
ERROR in ./app/index.scss Module build failed:
Error: Didn't get a result from child compiler     
at Object.<anonymous> (/home/u65/src/repo/desktop-prototype/
node_modules/extract-text-webpack-plugin/loader.js:90:22)
at Tapable.<anonymous> (/home/u65/src/repo/desktop-prototype/node_modules/webpack/lib/Compiler.js:210:10)     at /home/u65/src/repo/desktop-prototype/node_modules/webpack/lib/Compiler.js:397:12     at Tapable.next (/home/u65/src/repo/desktop-prototype/node_modules/webpack/node_modules/tapable/lib/Tapable.js:69:11)     at Object.<anonymous> (/home/u65/src/repo/desktop-prototype/node_modules/extract-text-webpack-plugin/loader.js:77:5)     at Tapable.next (/home/u65/src/repo/desktop-prototype/node_modules/webpack/node_modules/tapable/lib/Tapable.js:71:37)     at CachePlugin.<anonymous> (/home/u65/src/repo/desktop-prototype/node_modules/webpack/lib/CachePlugin.js:40:4)     at Tapable.applyPluginsAsync (/home/u65/src/repo/desktop-prototype/node_modules/webpack/node_modules/tapable/lib/Tapable.js:73:13)     at Tapable.<anonymous> (/home/u65/src/repo/desktop-prototype/node_modules/webpack/lib/Compiler.js:394:9)     at Tapable.<anonymous> (/home/u65/src/repo/desktop-prototype/node_modules/webpack/lib/Compilation.js:534:13)
<SNIP>
ERROR in ./~/raw-loader!./~/autoprefixer-loader!
./node_loaders/sass-sync-loader.js?sync&outputStyle=compact&includePaths[]=
/home/u65/src/repo/desktop-prototype/.generated/designassets&
includePaths[]=/home/u65/src/repo/desktop-prototype/.generated/design-
properties&includePaths[]=/home/u65/src/repo/desktop-prototype/
app!./app/index.scss     
Module build failed: Child extract-text-webpack-plugin:         
+ 1 hidden modules
Child extract-text-webpack-plugin:         
+ 1 hidden modules

@Richard_Boardman指出,Mac不区分大小写,但Linux区分大小写。因此,任何大小写拼写错误都可以在Mac开发环境中正常工作,但在部署时会失败。

您可以通过使用Webpack插件(如区分大小写的路径Webpack插件),强制Webpack在开发服务器和构建中对其文件名和路径匹配更加严格,这样拼写错误在开发框中时会失败,而不是在服务器上。

一旦你安装了它,你可以写一些测试,比如:

describe("Case-Sensitive Paths Plugin", () => {
  it('shouldn''t interfere with correctly-spelled imports', () => {
    const getUser1 = require('../src/utils/api');
    expect(getUser1).toBeDefined();
  });
  it('should cause mistakes in filename case to fail import', () => {
    expect(() => {const getUser2 = require('../src/utils/API');}).toThrow();
  });
  it('should cause mistakes in path case to fail import', () => {
    expect(() => {const getUser3 = require('../src/Utils/api');}).toThrow();
  });
});