[英]Webpack "Module not found: Error: Can't resolve './src/'"
I have two HTML pages, each will include it's own bundle.我有两个 HTML 页面,每个页面都包含它自己的包。 Here is my project structure:
这是我的项目结构:
public/
-- dist/
src/
-- firebase/
-- network/
webpack.config.js
Here's my webpack config:这是我的 webpack 配置:
const path = require('path');
const CleanTerminalPlugin = require('clean-terminal-webpack-plugin');
module.exports = {
mode: "development",
entry: {
network: path.resolve(__dirname, 'src') + '/network/index.ts',
firebase: path.resolve(__dirname, 'src') + '/firebase/index.ts'
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
output: {
path: path.resolve(__dirname, 'public') + '/dist',
},
plugins: [new CleanTerminalPlugin()]
};
I expect this to create two bundles in public/dist
with the names firebase.js
and network.js
.我希望这会在
public/dist
中创建两个名为firebase.js
和network.js
的包。 Instead I get an error:相反,我得到一个错误:
ERROR in main Module not found: Error: Can't resolve './src/' in 'path/to/project/root'
It also says Field 'browser' doesn't contain a valid alias configuration /path/to/project/root/src/index doesn't exist
And repeats that for .tsx
, .ts
and .js
它还说
Field 'browser' doesn't contain a valid alias configuration /path/to/project/root/src/index doesn't exist
并对.tsx
、 .ts
和.js
重复
I don't know why it's looking for an index.*
file in my src/
.我不知道它为什么要在我的
src/
中寻找index.*
文件。 I didn't specify that as an entry file.我没有将其指定为入口文件。 If I create a
src/index.ts
it builds, but only makes one bundle called main
which is not my expected behavior.如果我创建一个
src/index.ts
它会构建,但只会创建一个名为main
的包,这不是我的预期行为。
It ended up being a really stupid issue, but I'll post the answer in case someone needs it.它最终成为一个非常愚蠢的问题,但我会发布答案以防有人需要它。
I was invoking webpack with webpack./src
but webpack
without the ./src
worked as expected.我正在使用
webpack./src
调用 webpack,但没有webpack
的./src
按预期工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.