找不到模块:错误:无法解析“ C:\ HK \ Vue-learning \ testapp1 \ src”中的“ ./router”

时间:2020-02-17 05:40:06

标签: vue.js webpack vuejs2 vuex vue-router

我是Vue js的新手。我已经安装了基本的vue模板并添加了用于捆绑的Web包。但是,当我使用“ webpack --config webpack.config.js”构建应用程序时,出现以下错误。

** ./src/main.ts中的错误 找不到模块:错误:无法解析“ C:\ HK \ Vue-learning \ testapp1 \ src”中的“ ./router” @ ./src/main.ts 2:0-30 7:12-18

./ src / main.ts中的错误 找不到模块:错误:无法解析“ C:\ HK \ Vue-learning \ testapp1 \ src”中的“ ./store” @ ./src/main.ts 3:0-28 8:11-16

错误,错误:子编译失败: 找不到输入模块:错误:无法解析“ C:\ HK \ Vue-learning \ testapp1”中的“ C:\ HK \ Vue-learning \ testapp1 \ static \ index.html”: 错误:无法解析“ C:\ HK \ Vue-learning \ testapp1”中的“ C:\ HK \ Vue-learning \ testapp1 \ static \ index.html”

compiler.js:79 childCompiler.runAsChild [testapp1] / [html-webpack-plugin] /lib/compiler.js:79:16

Compiler.js:343编译 [testapp1] / [webpack] /lib/Compiler.js:343:11

Compiler.js:681 hooks.afterCompile.callAsync.err [testapp1] / [webpack] /lib/Compiler.js:681:15

Hook.js:154 AsyncSeriesHook.lazyCompileHook [testapp1] / [可点击] /lib/Hook.js:154:20

Compiler.js:678 Compiler.seal.err [testapp1] / [webpack] /lib/Compiler.js:678:31

Hook.js:154 AsyncSeriesHook.lazyCompileHook [testapp1] / [可点击] /lib/Hook.js:154:20

Compilation.js:1423 hooks.optimizeAssets.callAsync.err [testapp1] / [webpack] /lib/Compilation.js:1423:35

Hook.js:154 AsyncSeriesHook.lazyCompileHook [testapp1] / [可点击] /lib/Hook.js:154:20

Compilation.js:1414 hooks.optimizeChunkAssets.callAsync.err [testapp1] / [webpack] /lib/Compilation.js:1414:32

index.js:321 taskRunner.run [testapp1] / [terser-webpack-plugin] /dist/index.js:321:9

TaskRunner.js:48 TaskRunner.run [testapp1] / [terser-webpack-plugin] /dist/TaskRunner.js:48:7

index.js:227 TerserPlugin.optimizeFn [testapp1] / [terser-webpack-plugin] /dist/index.js:227:18

Hook.js:154 AsyncSeriesHook.lazyCompileHook [testapp1] / [可点击] /lib/Hook.js:154:20

Compilation.js:1409 hooks.additionalAssets.callAsync.err [testapp1] / [webpack] /lib/Compilation.js:1409:36

Hook.js:154 AsyncSeriesHook.lazyCompileHook [testapp1] / [可点击] /lib/Hook.js:154:20

Compilation.js:1405 hooks.optimizeTree.callAsync.err [testapp1] / [webpack] /lib/Compilation.js:1405:32

Hook.js:154 AsyncSeriesHook.lazyCompileHook [testapp1] / [可点击] /lib/Hook.js:154:20

Compilation.js:1342 Compilation.seal [testapp1] / [webpack] /lib/Compilation.js:1342:27

Compiler.js:675piler.finish.err [testapp1] / [webpack] /lib/Compiler.js:675:18

Compilation.js:1261 hooks.finishModules.callAsync.err [testapp1] / [webpack] /lib/Compilation.js:1261:4

Hook.js:154 AsyncSeriesHook.lazyCompileHook [testapp1] / [可点击] /lib/Hook.js:154:20

Compilation.js:1253 Compilation.finish [testapp1] / [webpack] /lib/Compilation.js:1253:28

Compiler.js:672 hooks.make.callAsync.err [testapp1] / [webpack] /lib/Compiler.js:672:17

Compilation.js:1185 _addModuleChain [testapp1] / [webpack] /lib/Compilation.js:1185:12

Compilation.js:1044 errorAndCallback.bail.err [testapp1] / [webpack] /lib/Compilation.js:1044:6

Compilation.js:1075 moduleFactory.create [testapp1] / [webpack] /lib/Compilation.js:1075:14

NormalModuleFactory.js:401工厂 [testapp1] / [webpack] /lib/NormalModuleFactory.js:401:22

“ index.html”的子html-webpack-plugin:

找不到入口模块中的错误:错误:无法解析'C:\ HK \ Vue-learning \ testapp1'中的'C:\ HK \ Vue-learning \ testapp1 \ static \ index.html' npm ERR!代码ELIFECYCLE npm ERR!错误2 npm ERR! testapp1@0.1.0 build:prod:webpack --config webpack.config.js npm ERR!退出状态2 npm ERR! npm ERR!在testapp1@0.1.0 build:prod脚本处失败。 npm ERR! npm可能不是问题。上面可能还有其他日志记录输出。

npm ERR!可以在以下位置找到此运行的完整日志: npm ERR! C:\ Users \ AppData \ Roaming \ npm-cache_logs \ 2020-02-17T04_54_32_639Z-debug.log **

 webpack.config.js
------------------------
const { VueLoaderPlugin } = require('vue-loader');
const path = require('path');

const HtmlWebpackPlugin = require('html-webpack-plugin');

const env = process.env.NODE_ENV;

const config = {
entry: path.join(__dirname, 'src', 'main.ts'),
mode: env,
output: {
publicPath: '/build',
},
optimization: {
splitChunks: {
  // Must be specified for HtmlWebpackPlugin to work correctly.
  // See: https://github.com/jantimon/html-webpack-plugin/issues/882
  chunks: 'all',
},
},
module: {
rules: [
  {
    test: /\.vue$/,
    loader: 'vue-loader',
  },
  {
    test: /\.js$/,
    exclude: /(node_modules|bower_components)/,
    loader: "babel-loader",
    exclude: /node_modules/,
},
{
    test: /\.ts$/,
    loader: "ts-loader",
    options: {
        appendTsSuffixTo: [/\.vue$/],
        transpileOnly: true
    }
},
{
    test: /\.css$/,
    loader: "css-loader"
}
],
},
plugins: [
new VueLoaderPlugin(),
new HtmlWebpackPlugin({
  filename: path.join(__dirname, 'dist', 'index.html'),
  template: path.join(__dirname, 'static', 'index.html'),
  inject: true,
}),
],
 };

module.exports = config;'

package.json

package.json

{
“name”: “testapp1”,
“version”: “0.1.0”,
“private”: true,
“scripts”: {
“serve”: “vue-cli-service serve”,
“build”: “vue-cli-service build”,
“build:prod”: “webpack --config webpack.config.js”,
“lint”: “vue-cli-service lint”
},
“dependencies”: {
“vue”: “^2.6.11”,
“vue-class-component”: “^7.2.2”,
“vue-property-decorator”: “^8.3.0”,
“vue-router”: “^3.1.5”,
“vuex”: “^3.1.2”
},
“devDependencies”: {
“@typescript-eslint/eslint-plugin”: “^2.18.0”,
“@typescript-eslint/parser”: “^2.18.0”,
“@vue/cli-plugin-eslint”: “~4.2.0”,
“@vue/cli-plugin-router”: “~4.2.0”,
“@vue/cli-plugin-typescript”: “~4.2.0”,
“@vue/cli-plugin-vuex”: “~4.2.0”,
“@vue/cli-service”: “~4.2.0”,
“@vue/eslint-config-standard”: “^5.1.0”,
“@vue/eslint-config-typescript”: “^5.0.1”,
“eslint”: “^6.7.2”,
“eslint-plugin-import”: “^2.20.1”,
“eslint-plugin-node”: “^11.0.0”,
“eslint-plugin-promise”: “^4.2.1”,
“eslint-plugin-standard”: “^4.0.0”,
“eslint-plugin-vue”: “^6.1.2”,
“typescript”: “~3.7.5”,
“vue-template-compiler”: “^2.6.11”,
“vue-webpack”: “^1.10.2”,
“webpack-cli”: “^3.3.11”
},
“eslintConfig”: {
“root”: true,
“env”: {
“node”: true
},
“extends”: [
“plugin:vue/essential”,
“@vue/standard”,
“@vue/typescript/recommended”
],
“parserOptions”: {
“ecmaVersion”: 2020
},
“rules”: {}
},
“browserslist”: [
“> 1%”,
“last 2 versions”
]
}

0 个答案:

没有答案