我安装了@types/node。我正在使用纱线 2 (PnP)。好像 Typescript 找不到 @types/node 包?
yarn build
使用构建脚本运行时会webpack
显示有关无法解析模块(路径、缓冲区等)的错误
跑步tsc
节目TS2688: Cannot find type definition file for 'node'.
但是,运行“ts-node”确实可以正常工作。
我的 tsconfig.json 如下:
{
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src",
"module": "commonjs",
"target": "es6",
"jsx": "react",
"allowJs": true,
"moduleResolution": "node",
"esModuleInterop": true,
"lib": [
"ES2020",
"DOM"
],
"types": ["node"]
},
"include": [
"src/**/*"
]
}
我的 webpack.config.js
module.exports = {
mode: "development",
devtool: "inline-source-map",
entry: "./src/server.ts",
output: {
filename: "bundle.js"
},
resolve: {
extensions: [".tsx", ".ts", ".js"]
},
module: {
rules: [
{
test: /\.tsx?$/,
use: [{
loader: 'ts-loader',
options: {
transpileOnly: true,
experimentalWatchApi: true,
onlyCompileBundledFiles: true,
},
}],
exclude: /node_modules/,
}
]
}
};