繁体   English   中英

使用 nodejs 的外部文件

[英]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.

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