简体   繁体   English

使用 nodejs 的外部文件

[英]Using external files for nodejs

I faced a problem with adjusting paths for my project.我在调整项目路径时遇到了问题。 The project has following structure:该项目具有以下结构:

prj
 |-common
 |   |-types
 |      |-somefile.ts ...
 |
 |-server
 |   |-node_modules
 |   |-package.json ...
 |
 |-client
 |   |-node_modules
 |   |-package.json
 |   |-angular.json ...

somefile.ts一些文件.ts

import { Observable, Subject } from 'rxjs'; !!!Cannot find module 'rxjs' or its corresponding type declarations
export class Someclass {}

As you may see i want to reuse common types between server and client side.如您所见,我想在服务器端和客户端之间重用常见类型。 somefile.ts is easily imported in project via relative path. somefile.ts很容易通过相对路径导入到项目中。 But when the somefile.ts is used in some of the project, popups error for "rxjs" module.但是当在某些项目中使用somefile.ts时,“rxjs”模块会弹出错误。

How to properly configure package.json for projects?如何为项目正确配置 package.json?

If it's not a core module (you installed it), you need to give a path to node_modules folder.如果它不是核心模块(您安装了它),则需要提供node_modules文件夹的路径。 Which I can see there's two.我可以看到有两个。 You need to make sure which one of them contains rxjs .您需要确保其中哪一个包含rxjs Then give the path like this:然后给出这样的路径:

const rxjs = require("../../server/node_modules/rxjs");

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

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