mir*_*fer 5 typescript next.js
我正在尝试使用默认配置在 Next.js 项目中运行单个 ES 模块 .ts 文件以进行快速调试:
npx ts-node lib/my_module.ts
Run Code Online (Sandbox Code Playgroud)
这给了我这个错误:
Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
Run Code Online (Sandbox Code Playgroud)
我不想弄乱默认配置,所以寻找一种合理的方法来完成这项工作。
mir*_*fer 12
事实证明,我们可以将一个 ts-node 特定配置部分添加到tsconfig.json.
这不会干扰 Next.js 编译器选项。
...
"ts-node": {
"compilerOptions": {
"module": "CommonJS"
}
},
...
Run Code Online (Sandbox Code Playgroud)
另请参阅https://github.com/TypeStrong/ts-node/issues/935#issuecomment-913179458。
之后,您可以简单地运行一个带有ts-node lib/my_module.ts.
| 归档时间: |
|
| 查看次数: |
3403 次 |
| 最近记录: |