亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么 webpack 不能正確編譯 ts 文件?

為什么 webpack 不能正確編譯 ts 文件?

慕后森 2022-10-08 15:18:58
我有一個簡單的功能,./src/ts/bundle.ts但它會產生錯誤,我不知道為什么?ERROR in ./src/ts/bundle.ts 6:22Module parse failed: Unexpected token (6:22)You may need an appropriate loader to handle this file type, currently, no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders|  */|> function sayHI ( text : string ){|     console.log ( text );| }function sayHI ( text : string ){    console.log ( text );}包.json{  "name": "document",  "version": "1.0.0",  "description": "",  "main": "sample.js",  "scripts": {    "build": "webpack"  },  "keywords": [],  "author": "",  "license": "ISC",  "devDependencies": {    "ts-loader": "^7.0.5",    "typescript": "^3.9.5",    "webpack": "^4.43.0",    "webpack-cli": "^3.3.11"  }}這是 webpack.config.js/** *  * @package Webpack * main configuration file for the webpack bundler */const path = require("path");module.exports = {    watch: true,    devtool: 'source-map',    mode: 'development',    entry: {        bundle: path.resolve(__dirname, 'src/ts/bundle.ts'),    },    output: {        path: path.resolve(__dirname, 'dist/js/'),        filename: '[name].js'    },    module: {        rules: [{            test: /\.ts$|js/,            use: 'ts-loader',            include: [                path.resolve(__dirname, 'src/js/')            ]        }]    }}
查看完整描述

1 回答

?
慕森卡

TA貢獻1806條經驗 獲得超8個贊

你的 中有一個 typeo webpack.config.js,要么刪除它,要么修復它。/src/ts/您已告訴它僅在某些文件夾上運行,因此您指定的文件位于ts-loader.


// ...rest of webpack.config.js

    include: [

        path.resolve(__dirname, 'src/js/')

    ]

// ...rest of webpack.config.js


// ...rest of webpack.config.js

    include: [

        path.resolve(__dirname, 'src/ts/')

    ]

// ...rest of webpack.config.js


查看完整回答
反對 回復 2022-10-08
  • 1 回答
  • 0 關注
  • 162 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號