denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
94.05k stars 5.23k forks source link

Error loading package.json: Not a directory #17947

Open lbguilherme opened 1 year ago

lbguilherme commented 1 year ago
import "npm:@sdkgen/node-runtime";

This fails on Deno 1.31.1 with:

error: Uncaught Error: Error loading package.json at /mnt/node_modules/.deno/@sdkgen+node-runtime@2.2.0/node_modules/decimal.js/decimal.js/package.json. Not a directory (os error 20)
    at resolveExports (internal:deno_node_loading/02_require.js:318:14)
    at Function.Module._findPath (internal:deno_node_loading/02_require.js:357:31)
    at Function.Module._resolveFilename (internal:deno_node_loading/02_require.js:618:27)
    at Function.Module._load (internal:deno_node_loading/02_require.js:467:27)
    at Module.require (internal:deno_node_loading/02_require.js:678:19)
    at require (internal:deno_node_loading/02_require.js:818:16)
    at Object.<anonymous> (file:///mnt/node_modules/.deno/@sdkgen+node-runtime@2.2.0/node_modules/@sdkgen/node-runtime/dist/src/encode-decode.js:40:22)
    at Object.<anonymous> (file:///mnt/node_modules/.deno/@sdkgen+node-runtime@2.2.0/node_modules/@sdkgen/node-runtime/dist/src/encode-decode.js:374:4)
    at Module._compile (internal:deno_node_loading/02_require.js:745:34)
    at Object.Module._extensions..js (internal:deno_node_loading/02_require.js:778:10)

The same import works on Deno 1.30.3, so this is a regression.

Importing decimal.js directly works, but not indirectly. Both modules are commonjs.

bartlomieju commented 1 year ago

I assume this only happens with --node-modules-dir flag, otherwise I can't repeat the problem.

Also I get the same error on both 1.30.3 and 1.31.0.

lbguilherme commented 1 year ago

Sorry, I missed one step: you also need to have a package.json file.

This is a full repro:

npm init -y
echo 'import "npm:@sdkgen/node-runtime";' > index.ts
deno run -A index.ts