[英]Using external files for nodejs
我在調整項目路徑時遇到了問題。 該項目具有以下結構:
prj
|-common
| |-types
| |-somefile.ts ...
|
|-server
| |-node_modules
| |-package.json ...
|
|-client
| |-node_modules
| |-package.json
| |-angular.json ...
一些文件.ts
import { Observable, Subject } from 'rxjs'; !!!Cannot find module 'rxjs' or its corresponding type declarations
export class Someclass {}
如您所見,我想在服務器端和客戶端之間重用常見類型。 somefile.ts很容易通過相對路徑導入到項目中。 但是當在某些項目中使用somefile.ts時,“rxjs”模塊會彈出錯誤。
如何為項目正確配置 package.json?
如果它不是核心模塊(您安裝了它),則需要提供node_modules
文件夾的路徑。 我可以看到有兩個。 您需要確保其中哪一個包含rxjs
。 然后給出這樣的路徑:
const rxjs = require("../../server/node_modules/rxjs");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.