我得到了TypeScript代碼文件的錯誤,它看起來像一個常見的錯誤,但我無法解決這個問題。我是Visual Studio代碼的新手。Visual studio代碼:Connot編譯模塊,除非提供了--module標誌
Cannot compile modules unless the '--module' flag is provided
我得到了TypeScript代碼文件的錯誤,它看起來像一個常見的錯誤,但我無法解決這個問題。我是Visual Studio代碼的新手。Visual studio代碼:Connot編譯模塊,除非提供了--module標誌
Cannot compile modules unless the '--module' flag is provided
所以,我明白你的問題 - 這是非常常見的異常,並解決它,你應該分析compiler options
所以,如果你在tasks.json
您可以定義多個另外編譯代碼這樣的編譯參數
{
"version": "0.1.0",
// The command is tsc. Assumes that tsc has been installed using npm install -g typescript
"command": "tsc",
// The command is a shell script
"isShellCommand": true,
// Show the output window only if unrecognized errors occur.
"showOutput": "silent",
// args is the HelloWorld program to compile.
"args": ["-m", "commonjs", "HelloWorld.ts"],
// use the standard tsc problem matcher to find compile problems
// in the output.
"problemMatcher": "$tsc"
}
so -m
表示--module
編譯器命令。
所以,如果你使用tsconfig.json,你可以找到與模塊設置默認配置here
"module": "commonjs"
:
module
- 標誌,告訴編譯器使用的模塊系統commonjs
- 模塊系統我希望它能解決您的問題!祝你好運!
把這個設置放在tsconfig.json中是一個更好的方法,那麼它也可以與其他的構建系統一起工作。 – DCoder
注意:添加tsconfig.json後,只有重新啓動可視代碼後,對智能感知的更改纔會生效。 –
你使用tsconfig.json還是默認使用? –
是的,我使用的是tsconfig.json – RaviMittal