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

New version doesn't work with -r flag #144

Closed
1 task
malekim opened this issue Nov 15, 2022 · 12 comments · Fixed by esbuild-kit/cjs-loader#29
Closed
1 task

New version doesn't work with -r flag #144

malekim opened this issue Nov 15, 2022 · 12 comments · Fixed by esbuild-kit/cjs-loader#29

Comments

@malekim
Copy link

malekim commented Nov 15, 2022

Bug description

Usually I use tsx with nodemon and -r dotenv/config. Last version blocked that possibility, because tsx -r flag is overriding -r flag from the node environment.

I would expect, that -r flag will work like it was working before.

Reproduction

nodemon -r dotenv/config ./main.ts

With nodemon.json configuration:

{
  "ignore": [
    ".git*",
    "node_modules/**/node_modules"
  ],
  "verbose": true,
  "watch": [
    ".env",
  ],
  "execMap": {
    "ts": "tsx"
  }
}

Environment

System:
    OS: macOS 12.0.1
    CPU: (8) arm64 Apple M1 Pro
    Memory: 112.48 MB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.18.0 - /opt/homebrew/opt/node@16/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 8.19.2 - /opt/homebrew/opt/node@16/bin/npm

Can you contribute a fix?

  • I’m interested in opening a pull request for this issue.
@malekim malekim added bug Something isn't working pending triage labels Nov 15, 2022
@privatenumber
Copy link
Owner

Are you able to reproduce this without nodemon?

@malekim
Copy link
Author

malekim commented Nov 15, 2022

Yes, the command like that will also produce an error:

tsx -r dotenv/config ./main.ts

For version ^3.12.0 that command doesn't work, for version 3.11.0 it works perfectly.

@privatenumber
Copy link
Owner

Works fine for me.

Please provide a reproduction repository link.

@moltar
Copy link

moltar commented Nov 16, 2022

I think this is the cause of our failures too, which is the same use case: -r dotenv/config.

Stack trace:

screenshot-20221116T115232-mEQLAT3i

@moltar
Copy link

moltar commented Nov 16, 2022

Can confirm that downgrading to 3.11.0 had resolved the error above.

@privatenumber
Copy link
Owner

Can you provide a minimal reproduction? I can't help if I can't reproduce it.

@privatenumber
Copy link
Owner

@moltar @malekim
I'd like to help but I need more information. Can either of you share a reproduction?

Will have to close this otherwise.

@moltar
Copy link

moltar commented Nov 21, 2022

git clone https://github.com/moltar/tsx-exp
cd tsx-exp
npm i
npm t
TypeError: Cannot read properties of null (reading 'includes')
    at Function.d.default._resolveFilename (/.../tsx-exp/node_modules/@esbuild-kit/cjs-loader/dist/index.js:1:1284)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at Module._preloadModules (node:internal/modules/cjs/loader:1276:12)
    at loadPreloadModules (node:internal/bootstrap/pre_execution:483:5)
    at prepareMainThreadExecution (node:internal/bootstrap/pre_execution:77:3)
    at node:internal/main/run_main_module:7:1

@moltar
Copy link

moltar commented Nov 21, 2022

Looks like something to do with the baseUrl in tsconfig.json, as removing that also removes the error.

diff --git a/tsconfig.json b/tsconfig.json
index 326841b..2c57e7c 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,6 +1,5 @@
 {
   "extends": "tsconfigs/nodejs-executable",
   "compilerOptions": {
-    "baseUrl": "./src"
   }
 }
\ No newline at end of file
❯ npm t

> tsx-exp@1.0.0 test
> tsx -r dotenv/config ./index.ts

1

@privatenumber
Copy link
Owner

privatenumber commented Nov 22, 2022

Thanks @moltar I have a fix coming soon.

@malekim Can you confirm this is the same issue you're reporting? Based on your issue, it seems you're describing a bug in flag handling.

@privatenumber
Copy link
Owner

@moltar To get the fix, you can either update the cjs-loader dependency with npm update or simply re-install tsx.

@moltar
Copy link

moltar commented Nov 22, 2022

Thank you @privatenumber!!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants