Webpack认为有两个文件名只有大小写不同的文件。

3

我不知道为什么,在使用npm启动测试服务器的控制台上,我开始看到这些消息:

WARNING in ./app/scripts/models/plan.js
There is another module with an equal name when case is ignored.
This can lead to unexpected behavior when compiling on a filesystem with other case-semantic.
Rename module if multiple modules are expected or use equal casing if one module is expected.

WARNING in ./app/scripts/models/Plan.js
There is another module with an equal name when case is ignored.
This can lead to unexpected behavior when compiling on a filesystem with other case-semantic.
Rename module if multiple modules are expected or use equal casing if one module is expected.

然而,如果我执行ls命令,该目录中只有一个这样的文件,并且文件名是大写的。

ls -l                                                                                                
total 40
-rw-r--r--  1 antkong  staff  604 26 Mar 09:44 Plan.js

如何消除这个消息?

我正在使用OSX操作系统。

2个回答

1
因为我在一个模块中使用了import Plan from './models/plan';。在OSX上,它将解析为Plan.js。但是,在Linux或其他区分大小写的文件系统上运行代码将会出现异常。

补充一下@Anthony Kong刚才说的,对于那些可能会遇到和我一样的问题的人来说,如果你的文件名是./my_path/File,那么应该将其导入为import File from './my_path/File'而不是import File from './my_path/file' - intercoder

0
在我的情况下,我有以下的webpack.config.js文件:
module.exports = {
    entry: {
        viewline: './Webpack/src/viewline.js',
        dashboard: './Webpack/src/dashboard.js',
        account: './Webpack/src/account.js',
        shiftreport_index: './webpack/src/shiftreport-index.js'
    },
....

请注意,最后一条记录中的./webpack...使用小写字母w,而其他记录使用大写字母W。将所有字母都改为大写可以解决这个问题:
module.exports = {
    entry: {
        viewline: './Webpack/src/viewline.js',
        dashboard: './Webpack/src/dashboard.js',
        account: './Webpack/src/account.js',
        shiftreport_index: './Webpack/src/shiftreport-index.js'
    },
...

所以请确保你的情况在任何地方都被检查。C


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