模块解析失败:意外的令牌

安东尼

嘿得到下面的错误,我运行webpack命令:$> webpack --mode“ development”

堆栈跟踪:

Version: webpack 4.17.2
Time: 1357ms
Built at: 09/10/2018 8:13:26 PM
    Asset      Size  Chunks             Chunk Names
bundle.js  1.37 MiB    main  [emitted]  main
Entrypoint main = bundle.js
[0] fs (ignored) 15 bytes {main} [built]
[./node_modules/css-loader/index.js!./wwwroot/Source/Styles/app.css] ./node_modules/css-loader!./wwwroot/Source/Styles/app.css 165 bytes {main} [built]
[./node_modules/css-loader/index.js!./wwwroot/Source/Styles/site.css] ./node_modules/css-loader!./wwwroot/Source/Styles/site.css 207 bytes {main} [built]
[./node_modules/webpack/buildin/global.js] (webpack)/buildin/global.js 509 bytes {main} [built]
[./node_modules/webpack/buildin/module.js] (webpack)/buildin/module.js 519 bytes {main} [built]
[./wwwroot/Source/Script/app.ts] 221 bytes {main} [built]
[./wwwroot/Source/Script/site.ts] 274 bytes {main} [built] [failed] [1 error]
[./wwwroot/Source/Styles/app.css] 1.06 KiB {main} [built]
[./wwwroot/Source/Styles/site.css] 1.07 KiB {main} [built]
    + 30 hidden modules

ERROR in ./wwwroot/Source/Script/site.ts 25:8
Module parse failed: Unexpected token (25:8)
You may need an appropriate loader to handle this file type.
|
| class Animal {
>     name: string;
|     constructor(theName: string) { this.name = theName; }
|     move(distanceInMeters: number = 0) {
 @ ./wwwroot/Source/Script/app.ts 4:0-16

似乎在编译时无法识别我所有类中的属性。

**交易代码**

class Animal {
   name: string;
   constructor(theName: string) { this.name = theName; }
   move(distanceInMeters: number = 0) {
     console.log(`${this.name} moved 
     ${distanceInMeters}m.`);
  }
}

tsconfig

{
  "compilerOptions": {
    "outDir": "./app/",
    "noImplicitAny": true,
    "module": "es6",
    "target": "es5",
    "allowJs": true,
    "sourceMap": true
  }
}

package.json

    {
  "name": "ExposureAPI",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "wbp": "webpack"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@babel/core": "^7.0.0",
    "@babel/preset-env": "^7.0.0",
    "@types/jquery": "^3.3.6",
    "@types/underscore": "^1.8.9",
    "babel-loader": "^8.0.2",
    "bootstrap": "^4.1.3",
    "css-loader": "^1.0.0",
    "gulp-babel": "^8.0.0",
    "jquery": "^3.3.1",
    "popper.js": "^1.14.4",
    "style-loader": "^0.22.1",
    "ts-loader": "^4.5.0",
    "typescript": "^3.0.1",
    "underscore": "^1.9.1",
    "webpack": "^4.17.2",
    "webpack-cli": "^3.1.0"
  },
  "dependencies": {
    "@types/simplemde": "^1.11.7",
    "simplemde": "^1.11.2"
  }
}

webpack.config.js

    const path = require('path');

    module.exports = {
        entry: './wwwroot/Source/Script/app.ts',
        module: {
            rules: [
                {
                    test: /\.tsx?$/,
                    use: 'ts-loader',
                    exclude: /node_modules/,
                    devtool: 'inline-source-map'
                }
            ]
        },
        resolve: {
            extensions: [ '.tsx', '.ts', '.js' ]
        },
        output: {
            path: path.resolve(__dirname, 'wwwroot/App'),
            filename: 'bundle.js'
        },
        module: {
            rules: [
                {
                    test: /\.css$/,
                    exclude: ['node_modules'],
                    use: [
                        { loader: "style-loader" },
                        { loader: "css-loader" }
                    ]
                }]
        }


    };

谢谢

塞尔克斯

显然是因为您module在webpack配置对象中具有两个属性而发生的

给定的JS对象每个键只能包含一个值-一个值将丢失。并且在这种情况下,后者覆盖了前者,因此webpack最终在没有打字机加载器配置的情况下进行了配置。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

webpack tsx 模块解析失败:意外的令牌

模块解析失败:意外的令牌离子3

Vue 模块解析失败:意外的令牌

模块解析失败:意外的令牌(11:19)

如何解决模块解析失败:意外的令牌?

模块解析失败:使用webpack-dev-server的意外令牌

模块解析失败:React Component Render上的意外令牌

Webpack 4基本React js hello world因“模块解析失败:意外令牌”而失败

模块解析失败:意外字符'@'

Webpack 无法解析打字稿文件。模块解析失败:意外的令牌

模块构建失败:SyntaxError:意外令牌

模块解析失败:使用 webpack 5 时出现意外令牌

ons-navigator:错误:模块解析失败:意外令牌(330:6)

模块解析失败:构建与Webpack交互时出现意外的令牌(6:16)

React JS:index.css 1:0中的错误(模块解析失败:意外令牌(1:0))

模块解析失败:意外令牌(1:0)vue.js vuex存储

模块解析失败:Webpack Typescript加载器中出现意外令牌

React和Webpack模块解析失败:/testimonials.js意外令牌(6:4)

模块解析失败:heroku 部署时出现意外令牌 (14:6)

模块解析失败:使用babel-loader发生意外的令牌(9:37)

模块解析失败:意外的令牌。react-native / index.js“ typeof”运算符

vue js 服务问题 - 模块解析失败:意外令牌 (763:13)

fsevents导致模块解析失败:意外字符'

模块解析失败:意外字符'@'(1:0)

Nuxt - 模块解析失败:意外字符“#”

webpack模块解析失败意外字符“ @”

模块解析失败:* .ts意外字符“ @”

反应-模块解析失败:意外的令牌。您可能需要适当的加载程序来处理此文件类型

React / Webpack-“模块解析失败:意外的令牌-您可能需要适当的加载器来处理此文件类型。”