yarn+ts节点:找不到模块fs



我有带几个包(w1、w2、w3(的Yarn工作区;w3正在使用fs库。

我想使用ts-node运行w1,如下所示:yarn workspace w1 start,其中起始为node-ts src/index.ts

然而我得到:

error TS2307: Cannot find module 'fs' or its corresponding type declarations.

此错误来自w3工作区;w3目录中的简单编译tsc可以很好地工作。

我尝试安装@types/node,它适用于tsc,但不适用于ts-node

这是一个对我有效的配置,在我的tsconfig.json中,我在typeRoots:中指定了

{  
"compilerOptions": {
"typeRoots": ["node_modules/@types"]
}
}

在我的包.json中,我有:

{
"scripts": {
"start": "ts-node src/index.ts",
},
"dependencies": {
"typescript": "^4.6.2",
"ts-node": "^9.1.1"
}
}

还要检查您是否已正确设置tsconfig中工作场所的引用。

最新更新