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
The nest build
Command may Resolve Module Paths Incorrectly
#838
Comments
nest build
Command Resolves may Resolve Module Paths Incorrectly nest build
Command may Resolve Module Paths Incorrectly
Repro repository created at https://github.com/astormnewrelic/nestjs-compiler-repro |
@kamilmysliwiec I'm gonna need some input here: I found that the issue comes from the tsconfig-paths's createMatchPath function and using |
Thanks for reporting @astormnewrelic. @jmcdo29 if there's a way we could fix it at the compiler level, that would be great 👍 would you like to dive into this? |
As anyone using the |
We can try to read it and - in case it doesn't exist/cannot be found - catch the error and fallback to the default value |
I'm not 100% sure but this property might be available already (somewhere in the compiler's code). I would have to double-check though @jmcdo29 😅 |
Guess I'll start digging. The other option I'm thinking of is updating the
|
It was set to be |
I've been thinking on this for a few days now. How do we handle a directory structure like above? If we look in |
@jmcdo29 @kamilmysliwiec Is there anything we can do to help triage this and move along to a solution? It sounds like you're caught in a "doing the right thing means breaking backward compatibility trap" -- which I can sympathize with. I know it's easy for me to say this but this might be a situation where it's best to bite the bullet and change the behavior to only scan If you can't apply a generic fix, would you be open to a one off special case for the |
@astormnewrelic The problem lies in how @kamilmysliwiec I'm in support of the breaking change back to setting the |
I can't agree on setting the I still believe there's a way to fix this issue without introducing other ones. I will look into this asap. |
Fixed in 7.5.2 |
Hello! It looks like some similar problem has been introduced in @nestjs/cli@10.
I also have the following path configured in my tsconfig.json:
After I compile (commonJs) the application with cli version 10.0.5, I get this error when trying to run it:
I checked and found out that it happened because the require equivalent to the /command import is just not present in the generated js. I downgraded to @nestjs/cli@9.5.0 and I tried to compile and run it again, and everything went fine. |
I'm just commenting here because I can't open a proper issue right now, but as soon as I can I'll create a repo to simulate this problem to do so. I know it's closed 3 years ago. Edit: Just to make it clearer, @micalevisk. Commenting here is important because someone with the same problem that cares to google it can now find a solution to it until it is fixed. You're welcome. |
I'm submitting a...
We've had some of our users report problems getting New Relic's Node.js Agent working with a NestJS project. We think we've tracked the problem down to what looks like a bug in
lib/compiler/hooks/tsconfig-paths.hook.ts
. We'd like to get this fixed, but we're not 100% sure what the intended behavior of this hook/plugin is and unsure how to go about a PR safely.Current behavior
When running
nest build
/npm run build
, ifimports
a CommonJS module fromnode_modules
then the compiled output of the program will contain a
require
statement with an incorrect path. This creates a problem for users of the Node.js agent, as our configuration can be stored in the root of a project in a file namednewrelic.js
(and our NPM module name is alsonewrelic
).Expected behavior
When resolving module paths,
nest build
should prefer modules installed innode_modules
to a javascript file in the root of a project.Minimal reproduction of the problem with instructions
See also: https://github.com/astormnewrelic/nestjs-compiler-repro
$ nest new project-name
(choosing an NPM managed project)$ cd project-name
$ npm install newrelic
$ touch newrelic.js
src/main.js
so it matches the program below$ npm run build
./dist/main.js
Expected Behavior:
Compiled output contains:
const newrelic_1 = require("newrelic");
Actual Behavior:
Compiled output contains:
const newrelic_1 = require("../newrelic");
Modified Program: (mentioned in step #5)
What is the motivation / use case for changing the behavior?
We'd like users of the New Relic Node.js agent to be able to more easily use the Agent with a Nest application. This is not a theoretical problem -- we have users report this problem to us.
We'd also like the Nest compilation process to match the behavior of a stock typescript application as much as possible.
Environment
The text was updated successfully, but these errors were encountered: