简体   繁体   English

Node.js参考路径绝对

[英]Node.js reference path absolute

I have a Node.js project developed in WebStorm IDE 我有一个用WebStorm IDE开发的Node.js项目

My project structure is: 我的项目结构是:

A root folder named "root" that contains 2 folders: "main" and "typings". 一个名为“ root”的根文件夹,其中包含2个文件夹:“ main”和“ typings”。 "main" contains one file named "foo.ts", "typings" contains one file named "bar.d.ts". “ main”包含一个名为“ foo.ts”的文件,“ typings”包含一个名为“ bar.d.ts”的文件。

In foo.ts I added a reference path to bar.d.ts. 在foo.ts中,我为bar.d.ts添加了参考路径。

This works: 这有效:

///<reference path="../typings/bar.d.ts" />

This does not work (getting "File not found"): 这不起作用(获取“找不到文件”):

///<reference path="/typings/bar.d.ts" />

This does not work either: 这也不起作用:

///<reference path="/root/typings/bar.d.ts" />

How can I get rid of the 2 dots (..)? 如何摆脱2个点(..)?

How can I get rid of the 2 dots (..) 如何摆脱2个点(..)

You can if you provide absolute path on disk . 如果您提供磁盘上的绝对路径,则可以。 This is however not what you want. 但是,这不是您想要的。

If you want relative to project root , that isn't supported for reference tags. 如果要相对于项目root ,则参考标记不支持。

Fix 固定

Just use tsconfig.json and make sure it includes both foo and bar using eg files 只需使用tsconfig.json并确保它使用tsconfig.json 文件同时包含foo和bar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM