使用Node.js打印baseUrl
为了避免import
长path,我在我的tsconfig.json
使用Typescript baseUrl选项
这是我的tsconfig.json
:
{ "compilerOptions": { "target": "ES6", "module": "none", "removeComments": true, "rootDir": "./", "outDir": "Build", "moduleResolution": "node", "noImplicitAny": true, "pretty": true, "baseUrl": "./" }, "exclude": [ "node_modules", "Build" ] }
所以不要这样做
import foo from "../../../../hello/foo"
我这样做
import foo from "hello/foo"
在Typescript编译器中它工作的很好,但是当我用node.js运行我的应用程序时,我有这个错误:
module.js:474 throw err; ^ Error: Cannot find module 'hello/foo'
Ps:我不想要像在互联网上看到的那样replacerequire()
函数
那么我怎样才能让node.js和baseUrl一起工作,或者把打字机replace成"hello/foo"
到"../../../../hello/foo"
?
Typescript编译器版本:
Version 2.3.0-dev.20170303
当您使用node.js运行应用程序时,传递NODE_PATH
env参数
例:
set NODE_PATH=./src node server.js
- 节点与Chrome,实施instanceof,多个文件
- Typescript导入/作为vs导入/要求?
- TypeScript readline.createInterface引发exception
- Node.js process.stdin问题typescript(tty.ReadStream vs ReadableStream)
- 找不到模块'angular2 / angular2'
- 如何确保浏览器和node.js的兼容性JavaScript库?
- 如何使用ThreeJS Collada loader与TypeScript / Angular CLI?
- 节点读取模块/读取代码文件
- Angular 4 CanActivate guard不会加载与服务一起使用的组件; 简单的Observable.of(true)作品