webpack@4
& webpack-cli@3
를 사용 하여 typescript 데모를 빌드 [email protected]
했지만 오류가 발생했습니다. 코드는 간단합니다.
import {Subject} from "rxjs";
const stateChange = new Subject();
그리고 나는 실행 npm build
하고 얻는다 :
Module not found: Error: Can't resolve './internal/Observable' in 'D:\working\test\node_modules\rxjs\_esm5'
하지만 Observable.js
거기에 Observable.ts
옆에 추가 하고 webpack이 './internal/Observable'
모듈을 찾았 지만 여전히 다른 오류가 있습니다. 왜 webpack이 .js
파일을 인식하지 못 합니까? 나는 ts-loader@8
.
package.json
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "npx webpack --display-error-details --config webpack.config.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"lit-html": "^1.3.0",
"lite-html": "^0.2.4",
"ts-node": "^9.0.0"
},
"dependencies": {
"rxjs": "^6.6.3",
"ts-loader": "^8.0.11",
"typescript": "^4.0.5",
"webpack": "^4.44.2",
"webpack-cli": "^3.3.12"
}
}
tsconfig.json
{
"compilerOptions":{
"outDir": "dist",
"target": "ES5",
"inlineSourceMap": true,
"inlineSources": true,
"declaration": true,
"declarationDir": "dist",
"allowJs": true,
"lib": ["ES6", "DOM"],
"experimentalDecorators": true
},
"files": [
"src/index.ts"
]
}
webpack.config.js
const path = require('path');
module.exports = {
entry: {
index: './src/index.ts'
},
module: {
rules: [
{
test: /\.ts?$/,
use: 'ts-loader',
exclude: /node_modules/
}
]
},
output: {
filename: '[name].min.js',
path: path.resolve(__dirname, 'dist')
},
mode: ENV_PROD,
resolve: {
extensions: [ '.ts']
}
}
문제를 발견했습니다. resolve.extensions
옵션에 webpack.config.js
'.js'가 포함되어야합니다. 감사합니다 @Walid M
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다