简体   繁体   English

Webpack“找不到模块:错误:无法解析'./src/'”

[英]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.jsnetwork.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.

相关问题 找不到主模块中的 WEBPACK5 错误:错误:无法解析“./src” - WEBPACK5 ERROR in main Module not found: Error: Can't resolve './src' 找不到输入模块:错误:无法解析“ ./src” - Entry module not found: Error: Can't resolve './src' 找不到模块:错误:无法解析“ @ cycle / run” webpack 2.2.1 - Module not found: Error: Can't resolve '@cycle/run' webpack 2.2.1 webpack-找不到模块:错误:无法解析'jquery' - webpack - Module not found: Error: Can't resolve 'jquery' webpack:找不到模块:错误:无法解析(使用相对路径) - webpack: Module not found: Error: Can't resolve (with relative path) Webpack:找不到模块:错误:无法解析“./containers” - Webpack: Module not found: Error: Can't resolve './containers' Webpack:移动 webpack/react 文件的位置后,npm start “Module not found: Error: Can't resolve ...” - Webpack: npm start "Module not found: Error: Can't resolve ..." after moving location for webpack / react files 未找到 ./src/App.jsx 模块中的错误:错误:无法解析“./component/Footer” - ERROR in ./src/App.jsx Module not found: Error: Can't resolve './component/Footer' 找不到模块:错误:无法解析“/home/user/Desktop/my_app/src”中的“./app” - Module not found: Error: Can't resolve './app' in '/home/user/Desktop/my_app/src' 找不到入口模块:错误:无法解析'./src/index.js' - Entry module not found: Error: Can't resolve './src/index.js'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM