Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running the plugin as a standalone executable throws Error: Cannot find module 'tslib' #104

Closed
dprogm opened this issue Aug 5, 2023 · 7 comments · Fixed by #106
Closed

Comments

@dprogm
Copy link
Contributor

dprogm commented Aug 5, 2023

When using the plugin without any other dependency it throws the following error:

node:internal/modules/cjs/loader:1073
  throw err;
  ^

Error: Cannot find module 'tslib'
Require stack:
- /Users/workstation/Dev/test_grpc/node_modules/@ngx-grpc/protoc-gen-ng/main.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1070:15)
    at Module._load (node:internal/modules/cjs/loader:923:27)
    at Module.require (node:internal/modules/cjs/loader:1137:19)
    at require (node:internal/modules/helpers:121:18)
    at Object.<anonymous> (/Users/workstation/Dev/test_grpc/node_modules/@ngx-grpc/protoc-gen-ng/main.js:4:15)
    at Module._compile (node:internal/modules/cjs/loader:1255:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1309:10)
    at Module.load (node:internal/modules/cjs/loader:1113:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/workstation/Dev/test_grpc/node_modules/@ngx-grpc/protoc-gen-ng/main.js'
  ]
}

Node.js v20.3.0

Steps to reproduce:
Add a package.json with the following content:

{
  "devDependencies": {
    "@ngx-grpc/protoc-gen-ng": "^3.1.1"
  },
  "scripts": {
    "proto:generate": "protoc-gen-ng"
  }
}

Run from the root directory:

npm install
npm run proto:generate

Possible solution:
Add tslib as a dependency for package @ngx-grpc/protoc-gen-ng

@smnbbrv
Copy link
Owner

smnbbrv commented Aug 6, 2023

Hi, is that a real use-case scenario? Normally you would already have angular with all of its dependencies in place

This however should be fixed

@dprogm
Copy link
Contributor Author

dprogm commented Aug 6, 2023

Hello @smnbbrv,

I agree with you, this is not a usual use-case. However I am using the plugin in a bazel build which forces us to add this dependency explicitly because it is not a direct/implicit dependency of the plugin itself. Therefore this is just "nice to have" to have this fixed upstream. 😉

@smnbbrv
Copy link
Owner

smnbbrv commented Aug 7, 2023

I'm totally fine with this. Could you, please, prepare a PR with the dep?

@dprogm
Copy link
Contributor Author

dprogm commented Aug 7, 2023

Sure, I am going to prepare a PR.

@dprogm
Copy link
Contributor Author

dprogm commented Aug 11, 2023

Update: I was trying to reproduce this with a local setup.

  1. Clone this repository from latest commit
  2. npm ci
  3. npm run build:lib:protoc-gen-ng
  4. Create a folder locally with an empty package.json
  5. npm install -D /path/to/ngx-grpc/dist/protoc-gen-ng
  6. npx protoc-gen-ng

Result: No error!

If I am using the latest release 3.1.1 from npm the mentioned error is thrown. I guess it's because all of the installed dependencies in the root of ngx-grpc which are not available when fetching from npm. Now I am trying to build the package protoc-gen-ng in isolation, but I am not sure if this is how it's intended by the npm workflow. Should all (sub-)packages list their dependencies explicitly?

@smnbbrv
Copy link
Owner

smnbbrv commented Aug 13, 2023

Should all (sub-)packages list their dependencies explicitly?

of course, the root package.json is not anyhow getting into resulting published packages

@dprogm
Copy link
Contributor Author

dprogm commented Aug 13, 2023

Okay, thanks. Then I am preparing a fix for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants