Amin NAIRI
Amin NAIRI3w ago

Run JSR library from NPX

I have built a package that uses Deno internals at https://jsr.io/@aminnairi/tsconfig@0.2.0 but I'm having issues run this package from NPX as per the documentation. Using the npx jsr run @aminnairi/tsconfig command does not work, same thing when used with npx jsr run jsr:@aminnairi/tsconfig. Am I missing something? The command deno run -A jsr:@aminnairi/tsconfig works though.
JSR
@aminnairi/tsconfig - JSR
@aminnairi/tsconfig on JSR
4 Replies
marvinh.
marvinh.3w ago
Looks like Node doesn't support import.meta.main https://github.com/nodejs/node/issues/49440 . Also this SO question is related https://stackoverflow.com/questions/45136831/node-js-require-main-module
Amin NAIRI
Amin NAIRIOP3w ago
Thank you for your insights. I've updated my code and I'll try that then report here. Is it just me or has the jsr package been removed from npm? Looks like there is a 404 when trying to access the documentation Or woaw, looks like we are on the verge of an intl outage ! No package to be found on npmjs.com nor their servers Looks like a maintenance of their servers went wrong I guess 🤷‍♂️ After everything returned normal and testing the following command (prior to removing the import meta main) I still get this error
npx jsr run @aminnairi/tsconfig
(node:279) ExperimentalWarning: CommonJS module /usr/local/lib/node_modules/npm/node_modules/debug/src/node.js is loading ES Module /usr/local/lib/node_modules/npm/node_modules/supports-color/index.js using require().
Support for loading ES Module in require() is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
$ npm run @aminnairi/tsconfig
npm error Missing script: "@aminnairi/tsconfig"
npm error
npm error To see a list of scripts, run:
npm error npm run
npm error A complete log of this run can be found in: /root/.npm/_logs/2024-12-08T20_13_12_349Z-debug-0.log
Child process exited with: 1
npx jsr run @aminnairi/tsconfig
(node:279) ExperimentalWarning: CommonJS module /usr/local/lib/node_modules/npm/node_modules/debug/src/node.js is loading ES Module /usr/local/lib/node_modules/npm/node_modules/supports-color/index.js using require().
Support for loading ES Module in require() is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
$ npm run @aminnairi/tsconfig
npm error Missing script: "@aminnairi/tsconfig"
npm error
npm error To see a list of scripts, run:
npm error npm run
npm error A complete log of this run can be found in: /root/.npm/_logs/2024-12-08T20_13_12_349Z-debug-0.log
Child process exited with: 1
Tested in a Docker environment with the following
root@0665c2fa2519:~# node --version
v23.3.0
root@0665c2fa2519:~# npm --version
10.9.0
root@0665c2fa2519:~# npx --version
10.9.0
root@0665c2fa2519:~# uname -a
Linux 0665c2fa2519 6.6.63-1-lts #1 SMP PREEMPT_DYNAMIC Fri, 22 Nov 2024 15:39:56 +0000 x86_64 GNU/Linux
root@0665c2fa2519:~# node --version
v23.3.0
root@0665c2fa2519:~# npm --version
10.9.0
root@0665c2fa2519:~# npx --version
10.9.0
root@0665c2fa2519:~# uname -a
Linux 0665c2fa2519 6.6.63-1-lts #1 SMP PREEMPT_DYNAMIC Fri, 22 Nov 2024 15:39:56 +0000 x86_64 GNU/Linux
Looks like there is a similar issue using Bun
marvinh.
marvinh.3w ago
I see. Looks like the jsr run command invokes the active package manager's script feature. It doesn't run the package you pass to it https://github.com/jsr-io/jsr-npm/blob/52f93c31b00661a6cf2ba40a9663e02e5b199506/src/commands.ts#L194-L201 . I guess a workaround would be to import the package in a local file and run that file
Amin NAIRI
Amin NAIRIOP3w ago
Oh I understand, right. Thank you for the permalink! Should I open an issue or is it the expected behavior when using Deno and npx jsr ? Yeah, as I dig deeper, I saw that Deno, behind the scenes, transpiles the file to an index.js file that can be used to execute the command manually, but it looks cumbersome to do. I'll stick to Deno for now, thank you for your time!

Did you find this page helpful?