首页 > 解决方案 > vue:你可能需要一个合适的加载器来处理这个文件类型

问题描述

我将我的项目从 webpack3.x 升级到 webpack4.28.4,当我运行 webpack 进行生产时,它向我显示错误!


ERROR in ./src/router/_import_production.js 9:11
Module parse failed: Unexpected token (9:11)
You may need an appropriate loader to handle this file type.
| module.exports = function (file) {
|   return function () {
>     return import("@/views/" + file + ".vue");
|   };
| };
 @ ./src/router/index.js 8:14-58
 @ ./src/main.js

我用happypack来提高编译速度!

const HappyPack = require('happypack')
const os = require('os')
const happyThreadPool = HappyPack.ThreadPool({
    size: os.cpus().length
})

{
    test: /\.vue$/,
    loader: 'vue-loader',
    options: vueLoaderConfig
},
{
    test: /\.js$/,
    use: 'happypack/loader?id=babel',
    include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
}
new HappyPack({
    id: 'babel',
    loaders: [{
        loader: 'babel-loader',
        query: {
            cacheDirectory: true
        }
    }],
    threadPool: happyThreadPool,
    verbose: true
})

它没有用!任何人都可以解决我的问题吗?非常感谢!

标签: vue.jswebpack

解决方案


_import_production.js 修改这个文件

module.exports = file => require('@/views/' + file + '.vue').default

推荐阅读