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

Failed init cli on NPM #811

Open
schlichtanders opened this issue Mar 21, 2024 · 7 comments
Open

Failed init cli on NPM #811

schlichtanders opened this issue Mar 21, 2024 · 7 comments

Comments

@schlichtanders
Copy link

schlichtanders commented Mar 21, 2024

Failed init

I cannot initialize esm.sh with cli on npm

Error message

After running the code in npx reejs x https://esm.sh init in an already npm initialized repo I got this:

 INFO  Saving important data...
 TIP  If the error in your code is in any of the following extensions (.ts, .tsx, .jsx), kindly not focus on the line number as the line numbers depict the compiled code and not the original one. Add `DEBUG=true` to your environment variables to see the original code.
ReferenceError: Deno is not defined
    at https://esm.sh/|Node/v20.11.1 (reejs/0.17.0):434:1
    at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
    at async URLImport (file:///home/myhome/myproject/node_modules/@reejs/imports/URLImport.js:24:26)
    at async file:///home/myhome/myproject/node_modules/reejs/src/cli/cmds/x.js:118:22

After running reejs x https://esm.sh init in a new empty folder, I got this

[REEJS]  🛠️  Setting Up for first time.../sade.bundle.mjs
✓ https://esm.sh/v132/sade@1.8.1/node/sade.bundle.mjs in 1.3s
✓ https://esm.sh/ in 0.301s
 INFO  Saving important data...
 TIP  If the error in your code is in any of the following extensions (.ts, .tsx, .jsx), kindly not focus on the line number as the line numbers depict the compiled code and not the original one. Add `DEBUG=true` to your environment variables to see the original code.
ReferenceError: Deno is not defined
    at file:///home/myhome/myproject/.reejs/cache/532fae.js:434:1
    at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
    at async URLImport (file:///home/myhome/.npm-packages/lib/node_modules/reejs/node_modules/@reejs/imports/URLImport.js:24:26)
    at async file:///home/myhome/.npm-packages/lib/node_modules/reejs/src/cli/cmds/x.js:118:22

Additional info

  • esm.sh version: most recent
  • **Paste the reejs doctor report:
$ npx reejs doctor  # from my pre initialized npm project       
[reejs] Doctor
[RUNTIME] node
[VERSION] 0.17.0
[NODE_VER] 20.11.1
[REEJS_CACHE] 2 files
[REEJS_DIR] /home/[REDACTED]/myproject/.reejs , /home/[REDACTED]/myproject/.reejs
[REEJS_DIR_EXISTS] false
[PWD] /home/[REDACTED]/myproject
[USER_AGENT] Node/v20.11.1 (reejs/0.17.0)
$ reejs doctor  # from the new empty folder           
[reejs] Doctor
[RUNTIME] node
[VERSION] 0.17.0
[NODE_VER] 20.11.1
[REEJS_CACHE] 0 files
[REEJS_DIR] /home/[REDACTED]/.npm-packages/lib/node_modules/reejs/.reejs , /home/[REDACTED]/.julia/dev/tmp/esm-test/.reejs
[REEJS_DIR_EXISTS] false
[PWD] /home/[REDACTED]/myproject
[USER_AGENT] Node/v20.11.1 (reejs/0.17.0)
  • I tried to run this on an already existing package - maybe it is not designed to interact with an existing folder structure. EDIT: I added failure logs for the case of an empty repository
@renhiyama
Copy link
Contributor

Hi @schlichtanders thanks for reporting this issue. Reejs had removed support for Deno polyfill a few versions ago, due to unintended side affects.
To intentionally enable deno support, please add --deno parameter at the end of your reejs command.
(Since you're using npx, there's need of addititonal "--" before that parameter, in order to pass the additional parameter to reejs cli)

I currently tried that and then the deno polyfills loads up, but fails with the following error:

 INFO  Saving important data...
ReferenceError: __dirname is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/data/data/com.termux/files/usr/lib/node_modules/reejs/.reejs/cache/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at https://esm.sh/v135/@deno/shim-deno@0.16.0/node/shim-deno.mjs|Node/v18.16.1 (reejs/0.17.0):109:13666
    at https://esm.sh/v135/@deno/shim-deno@0.16.0/node/shim-deno.mjs|Node/v18.16.1 (reejs/0.17.0):109:458
    at https://esm.sh/v135/@deno/shim-deno@0.16.0/node/shim-deno.mjs|Node/v18.16.1 (reejs/0.17.0):110:3076
    at https://esm.sh/v135/@deno/shim-deno@0.16.0/node/shim-deno.mjs|Node/v18.16.1 (reejs/0.17.0):109:458
    at https://esm.sh/v135/@deno/shim-deno@0.16.0/node/shim-deno.mjs|Node/v18.16.1 (reejs/0.17.0):110:4066
    at https://esm.sh/v135/@deno/shim-deno@0.16.0/node/shim-deno.mjs|Node/v18.16.1 (reejs/0.17.0):109:458
    at https://esm.sh/v135/@deno/shim-deno@0.16.0/node/shim-deno.mjs|Node/v18.16.1 (reejs/0.17.0):110:59466
    at https://esm.sh/v135/@deno/shim-deno@0.16.0/node/shim-deno.mjs|Node/v18.16.1 (reejs/0.17.0):109:458
    at https://esm.sh/v135/@deno/shim-deno@0.16.0/node/shim-deno.mjs|Node/v18.16.1 (reejs/0.17.0):110:68331
    at https://esm.sh/v135/@deno/shim-deno@0.16.0/node/shim-deno.mjs|Node/v18.16.1 (reejs/0.17.0):109:458

I'll be debugging more of it later.

@renhiyama
Copy link
Contributor

Here's my personal notice that explains this new error, I've already encountered it before:
__dirname is defined in cjs, but not in mjs/esm.
esm.sh currently still cannot polyfill/fix this.

From my end/Reejs' end - it tries to polyfill __dirname at the start of each file where necessary. However I either disabled that support 2 months ago (that's when I last updated reejs) or reejs failed to polyfill __dirname from its side too.

@schlichtanders
Copy link
Author

I don't want to use deno, but want to use npm - hence I don't have deno installed

@schlichtanders
Copy link
Author

In case the cli cannot be installed on npm, it would be great to update the central website documentation to reflect this

@renhiyama
Copy link
Contributor

In case the cli cannot be installed on npm, it would be great to update the central website documentation to reflect this

Esm.sh's original service is to serve url imports, and is not a cli focused tool. The cli you see on deno & reejs - esm.sh only manages the importmaps file, but the underlying URL imports work is done by deno & reejs themselves.

You might want to look at jspm if you have problems running either of these two.

@ije
Copy link
Member

ije commented Mar 22, 2024

FYI, in v136 the CLI script will be deprecated, instead a vscode extension will be released for import map updating(support index.html/importmap.json/deno.json)

image

@schlichtanders
Copy link
Author

You might want to look at jspm if you have problems running either of these two.

My research already pointed me to jspm (took some time to find it). Thank you for the pointer, it really solves the cli part for import maps and also supports esm.sh

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

No branches or pull requests

3 participants