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

an attempted import of Node's built-in "zlib" module is being interpreted as being for a "zlib" NPM module #24274

Open
jeremyBanks opened this issue Jun 19, 2024 · 1 comment
Labels
bug Something isn't working correctly node compat

Comments

@jeremyBanks
Copy link
Contributor

Attempting to import npm:contentful-management produces the following error (the same as denoland/deno_ast#227, but per denoland/deno_ast#227 (comment) it's a different underlying issue):

> deno
Deno 1.44.2
exit using ctrl+d, ctrl+c, or close()
REPL is running with all permissions allowed.
To specify permissions, run `deno repl` with allow flags.
> import "npm:contentful-management"
Uncaught TypeError: Could not find npm package 'zlib' referenced by 'contentful-management@11.27.3'.
    at async <anonymous>:1:22
>

It seems like it might be interpreting a locally-ambiguous import of zlib that should be resolved as the built-in node module (node:zlib) instead as if it's an import for an NPM module of the same name (npm:zlib), but from a quick look I wasn't able to identify where the problematic import is actually happening.

@dsherret dsherret transferred this issue from denoland/deno_ast Jun 19, 2024
@dsherret dsherret added bug Something isn't working correctly node compat labels Jun 19, 2024
@jeremyBanks jeremyBanks changed the title CommonJS analysis interpreting an import of Node's built-in "zlib" module as being for a "zlib" NPM module an attempted import of Node's built-in "zlib" module is being interpreted as being for a "zlib" NPM module Jun 19, 2024
@jeremyBanks
Copy link
Contributor Author

I've tried to reduce this by using --node-modules-dir and editing it down locally. If I'm understanding correctly, these imports seem to resolve incorrectly when they're on the right-side of an export assignment.

// error: could not find package 'buffer'
module.exports = require("buffer");

// error: could not find package 'buffer'
exports = require("buffer");

// error: could not find package 'buffer'
function f() {
  exports = require("buffer");
}

//error: could not find package 'node:buffer'
module.exports = require("node:buffer");

If we make the export indirect, the imports are successful and we're able to use the re-exported value successfully.

// successful
const buffer = require("buffer");
module.exports = buffer;

// successful
const nodeBuffer = require("node:buffer");
module.exports = nodeBuffer;

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

No branches or pull requests

2 participants