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

npm:create-docusaurus ReferenceError: require is not defined #22732

Closed
littledivy opened this issue Mar 6, 2024 · 3 comments · Fixed by #24912
Closed

npm:create-docusaurus ReferenceError: require is not defined #22732

littledivy opened this issue Mar 6, 2024 · 3 comments · Fixed by #24912
Assignees
Labels
bug Something isn't working correctly node compat

Comments

@littledivy
Copy link
Member

$ deno run -A npm:create-docusaurus@latest my-website classic
[INFO] Creating new Docusaurus project...
[INFO] Installing dependencies with npm...
⚠️  The `--unstable` flag is deprecated and will be removed in Deno 2.0. Use granular `--unstable-*` flags instead.
Learn more at: https://docs.deno.com/runtime/manual/tools/unstable_flags
error: Uncaught (in promise) ReferenceError: require is not defined
if (require.main !== module) {
^
    at file:///home/divy/.cache/deno/npm/registry.npmjs.org/shelljs/0.8.5/src/exec-child.js:1:1
[ERROR] Dependency installation failed.
[INFO] The site directory has already been created, and you can retry by typing:

  `cd my-website`
  `npm install`
@littledivy littledivy added bug Something isn't working correctly node compat labels Mar 6, 2024
@lucacasonato
Copy link
Member

This still happens.

@kt3k
Copy link
Member

kt3k commented Aug 1, 2024

The below snippet looks like a smaller reproduction of the same issue:

import shelljs from "npm:shelljs";
shelljs.exec("echo 1")

shelljs.exec tries to call child_process.execFileSync with shelljs/src/exec-child.js as an entrypoint, and it seems handled as ESM instead of CJS.
https://github.com/shelljs/shelljs/blob/8a960da8383666024bfdb2eff709a4fdf66333ee/src/exec.js#L100

The issue seems disappearing if I use byonm settings (with package.json and node_modules)

@kt3k
Copy link
Member

kt3k commented Aug 1, 2024

in_npm_package check of ManagedCliNpmResolver seems returning false in the above case.

In that check function, root_dir_url becomes file:///Users/kt3k/Library/Caches/deno/npm/registry.npmjs.org/shelljs/0.8.5/node_modules/ in the above situation, and that directory doesn't exist. So this check never returns true for any specifier in the above invocation..

let root_dir_url = self.fs_resolver.root_dir_url();

I guess probably there's some error in creating npm_cache_dir.root_dir_url?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly node compat
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants