简体   繁体   中英

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

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. But when the somefile.ts is used in some of the project, popups error for "rxjs" module.

How to properly configure package.json for projects?

If it's not a core module (you installed it), you need to give a path to node_modules folder. Which I can see there's two. You need to make sure which one of them contains rxjs . Then give the path like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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