我正在尝试使用Webpack 4实现基本的ES6 import
/export
,但是Webpack似乎无法解析我的模块,虽然根据错误消息它正在正确地查找:
$ make
./node_modules/.bin/webpack --mode production src/app.js -o dist/bundle.js
Hash: 6decf05b399fcbd42b01
Version: webpack 4.1.1
Time: 339ms
Built at: 2018-3-11 14:50:58
1 asset
Entrypoint main = bundle.js
[0] ./src/app.js 41 bytes {0} [built]
ERROR in ./src/app.js
Module not found: Error: Can't resolve 'hello.js' in '/home/(myhomedir)/code/js/src'
@ ./src/app.js 1:0-31 2:0-5
这是我的设置(省略了node_modules
,dist
等):
$ npm ls --depth=0
.
├── webpack@4.1.1
└── webpack-cli@2.0.11
$ tree
.
├── Makefile
└── src
├── app.js
└── hello.js
Makefile:
webpack = ./node_modules/.bin/webpack --mode production
entry = src/app.js
webpack: $(entry)
$(webpack) $(entry) -o dist/bundle.js
src/app.js:
import {hello} from "hello.js";
hello();
src/hello.js:
function hello() {
alert("yes it's hello");
}
export { hello };
我尝试了很多在app.js
中的导入路径变化,但它们都得到相同的结果:无法解析
模块文件。我错过了什么?
babel-preset-env
将是您所需要的全部内容,因此不要使用旧的实践方法,因为很快它将会改变。像我一样上传您的代码。 - deadcoder0904