我正在尝试获得一个基本的 ES6 import
/export
使用 Webpack 4,而 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
生成文件:
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
,但它们都得到相同的结果:Can't resolve
模块文件。我错过了什么?