https://www.tslang.cn/docs/handbook/basic-types.html;html
使用Typescript開發Vue,一切準備就緒。但npm start 時,提示「node
ERROR in ./src/main.ts
Module build failed: TypeError: Cannot read property 'afterCompile' of undefined「錯誤。webpack
解決方法
將ts-loader從4.0下降到3.1.1解決問題。是因爲webpack和ts-loader版本不兼容形成的。web
來源--https://blog.csdn.net/nzyalj/article/details/78306435?locationNum=9&fps=1typescript
3.typescript import模塊的時候找不到省略.ts後綴的文件,此時在webpack.config.js中添加resolveshell
resolve: {
extensions: ['.ts', '.tsx','.js','.jsx'] ,
modules: ['src' ,'node_modules'],
},
4.在vscode 中用typescript開發node的時候,打開launch.json,按下ctrl +shift+b,而後選擇生成任務的設置圖標就會生成tasks.json,在這個任務配置文件中,能夠設置
執行launch命令前的命令配置以下:
launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch TypeScript",
"program": "${workspaceRoot}/dist/server.js",
"preLaunchTask": "compile",
}
]
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "compile",
"command": "gulp",
"type": "shell"
}
]
}