W
W
Webber2021-11-23 18:14:04
JavaScript
Webber, 2021-11-23 18:14:04

How to import files from a library?

I am doing a project on nestjs in the form of 2 services. Both services use the same code, I decided to move it to a separate library.
As a result, I created a ts-client package, uploaded it to git and installed it as "npm install git+ https://github.com/user/ts-client.git ".
Installed without problems, but the import does not work:

Error: Cannot find module 'ts-client/src/middleware/set-user-agent.middleware'


{
  "name": "ts-client",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@nestjs/axios": "^0.0.3",
    "@nestjs/common": "^8.2.2",
    "@types/accept-language-parser": "^1.5.3",
    "accept-language-parser": "^1.5.0"
  },
  "devDependencies": {
    "typeorm": "^0.2.41"
  }
}


And file: src -> middleware -> set-user-agent.middleware.ts
import {Injectable, NestMiddleware} from '@nestjs/common';

@Injectable()
export class SetUserAgentMiddleware implements NestMiddleware {
  use(req: any, res: any, next: () => void) {
    next()
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lssssssssssl, 2021-11-23
@lsssssssssl

Try to take advantage of what Nest itself offers. https://docs.nestjs.com/cli/libraries

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question