繁体   English   中英

找不到模块无法解决

[英]Module not found can't resolve

我已经尝试过查看这个类似问题的一些答案,但我从那里尝试过的解决方案都没有奏效。

我正在尝试在外部javascript文件中创建一个函数,我想在我的主javascript文件中使用该函数。

文件结构

webpack.config.js
app
-- index.js
-- test.js

webpack.config.js

module.exports = {
    devtool: "cheap-module-source-map",
    entry: "./app/index.js",
    output: {
        filename: "public/bundle.js"
    },
    module: {
        loaders: [
            {
                test: /\.jsx?$/,
                exclude: /(node_modules|bower_components)/,
                loader: 'babel-loader',
                query:
                {
                    presets: ['es2015']
                }
            }
        ]
    }
};

test.js

export default function test(message) {
    console.log(message);
}

index.js

"use strict"

import test from './app/test.js';

尝试运行webpack命令时,我收到错误:

ERROR in ./app/index.js

Module not found: Error: Can't resolve './app/test.js'

我已经尝试将文件路径更改为相对的,没有运气,我也尝试在webpack配置文件中添加多个入口点,但仍然没有运气。

作为答案发布,以便可以将其标记为已回答,来自评论:

您的导入路径是错误的,看起来您应该import test from './app/test.js';更改import test from './app/test.js'; import test from './test.js';

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM