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

multiple NPM compatibility issues #27894

Closed
scarf005 opened this issue Jan 31, 2025 · 8 comments
Closed

multiple NPM compatibility issues #27894

scarf005 opened this issue Jan 31, 2025 · 8 comments
Labels
invalid what appeared to be an issue with Deno wasn't node compat

Comments

@scarf005
Copy link
Contributor

scarf005 commented Jan 31, 2025

Version: Deno 2.1.9

All encountered while testing moltar/typescript-runtime-type-benchmarks#1267. might split into sub-issues later, but github UI doesn't seem to support creating them all at once

Reproduction Environment

deno repl --no-lock --unstable-sloppy-imports --unstable-detect-cjs

Directory imports

fp-ts

https://github.com/moltar/typescript-runtime-type-benchmarks/blob/606269200dd5432bf5c9f20aeee875a264adbc05/cases/io-ts.ts

> import * as mod from 'npm:fp-ts/Either'
Uncaught TypeError: Directory import /run/media/home/scarf/repo/typescript-runtime-type-benchmarks/node_modules/fp-ts/Either
  Caused by:
    Is a directory (os error 21)
    at async <anonymous>:1:34
> 

r-assign

https://github.com/moltar/typescript-runtime-type-benchmarks/blob/606269200dd5432bf5c9f20aeee875a264adbc05/cases/r-assign.ts

> import 'npm:r-assign/lib'
Uncaught TypeError: Directory import /run/media/home/scarf/repo/typescript-runtime-type-benchmarks/node_modules/r-assign/lib
  Caused by:
    Is a directory (os error 21)
    at async <anonymous>:1:22

stnl

https://github.com/moltar/typescript-runtime-type-benchmarks/blob/606269200dd5432bf5c9f20aeee875a264adbc05/cases/stnl.ts#L1-L3

> import compose from 'npm:stnl/compilers/validate-json/compose'
Uncaught TypeError: Unable to load /run/media/home/scarf/repo/typescript-runtime-type-benchmarks/node_modules/stnl/compilers/validate-json/compose
  Caused by:
    No such file or directory (os error 2)
    at async <anonymous>:1:53
> import compose from 'npm:stnl/compilers/validate-json'
Uncaught TypeError: Directory import /run/media/home/scarf/repo/typescript-runtime-type-benchmarks/node_modules/stnl/compilers/validate-json
  Caused by:
    Is a directory (os error 21)
    at async <anonymous>:1:53

Default import doesn't work

jointz

https://github.com/moltar/typescript-runtime-type-benchmarks/blob/606269200dd5432bf5c9f20aeee875a264adbc05/cases/jointz.ts

> import jointz from 'npm:jointz'
undefined
> jointz
{
  Validator: [Getter],
  FailedValidationError: [Getter],
  default: [class jointz]
}
> jointz.object()
Uncaught TypeError: jointz.object is not a function
    at <anonymous>:1:29

jetSchema

https://github.com/moltar/typescript-runtime-type-benchmarks/blob/606269200dd5432bf5c9f20aeee875a264adbc05/cases/jet-schema.ts

import jetSchema from 'npm:jet-schema';

console.log(jetSchema)
const schema = jetSchema({
  globals: [
  ],
})
{ schema: [Function (anonymous)], default: [Function: jetSchema] }
Uncaught TypeError: jetSchema is not a function
    at <anonymous>:3:16

Image

i think default import should work given it has default export defined.

Module not found

ts-utils

https://github.com/moltar/typescript-runtime-type-benchmarks/blob/606269200dd5432bf5c9f20aeee875a264adbc05/cases/ts-utils.ts

> import { object, number, boolean, string } from 'npm:@ailabs/ts-utils/dist/decoder'
Uncaught TypeError: Unable to load /run/media/home/scarf/repo/typescript-runtime-type-benchmarks/node_modules/@ailabs/ts-utils/dist/decoder
  Caused by:
    No such file or directory (os error 2)
    at async <anonymous>:1:66

Undefined properties

toi

https://github.com/moltar/typescript-runtime-type-benchmarks/blob/606269200dd5432bf5c9f20aeee875a264adbc05/cases/toi.ts

> import * as toi from 'npm:@toi/[email protected]'
undefined
>  const obj = () => toi.required().and(toi.obj.isplain());
  const req = () => toi.required();
  const num = () => toi.num.is();
  const str = () => toi.str.is();

  const isValid = obj().and(
    toi.obj.keys({
      number: req().and(num()),
      negNumber: req().and(num()),
      maxNumber: req().and(num()),
      string: req().and(str()),
      longString: req().and(str()),
      boolean: req().and(toi.bool.is()),
      deeplyNested: obj().and(
        toi.obj.keys({
          foo: req().and(str()),
          num: req().and(num()),
          bool: req().and(toi.bool.is()),
        }),
      ),
    }),
  );

Uncaught TypeError: Cannot read properties of undefined (reading 'isplain')
    at obj (<anonymous>:1:65)
    at <anonymous>:5:17
scarf005 added a commit to scarf005/typescript-runtime-type-benchmarks that referenced this issue Jan 31, 2025
skip when deno has compatibility issues with packages: denoland/deno#27894
@dsherret
Copy link
Member

might split into sub-issues later, but github UI doesn't seem to support creating them all at once

Yeah, it would be good to do that, but just as separate issues (I don't think sub-issues is necessary).

For exmaple, the first report within this issue is not a bug. The same thing happens in Node:

> node main.mjs    
node:internal/modules/run_main:104
    triggerUncaughtException(
    ^

Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import 'V:\scratch\node_modules\fp-ts\Either' is not supported resolving ES modules imported from V:\scratch\main.mjs
Did you mean to import "fp-ts/lib/Either.js"?
    at finalizeResolution (node:internal/modules/esm/resolve:263:11)
    at moduleResolve (node:internal/modules/esm/resolve:860:10)
    at defaultResolve (node:internal/modules/esm/resolve:984:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:688:12)
    at #cachedDefaultResolve (node:internal/modules/esm/loader:612:25)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:595:38)
    at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:248:38)
    at ModuleJob._link (node:internal/modules/esm/module_job:136:49) {
  code: 'ERR_UNSUPPORTED_DIR_IMPORT',
  url: 'file:///V:/scratch/node_modules/fp-ts/Either'
}

Node.js v23.5.0

@dsherret
Copy link
Member

Second one, not a bug:

> node main.mjs       
node:internal/modules/run_main:104
    triggerUncaughtException(
    ^

Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import 'V:\scratch\node_modules\r-assign\lib' is not supported resolving ES modules imported from V:\scratch\main.mjs
Did you mean to import "r-assign/lib/index.js"?
    at finalizeResolution (node:internal/modules/esm/resolve:263:11)
    at moduleResolve (node:internal/modules/esm/resolve:860:10)
    at defaultResolve (node:internal/modules/esm/resolve:984:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:688:12)
    at #cachedDefaultResolve (node:internal/modules/esm/loader:612:25)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:595:38)
    at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:248:38)
    at ModuleJob._link (node:internal/modules/esm/module_job:136:49) {
  code: 'ERR_UNSUPPORTED_DIR_IMPORT',
  url: 'file:///V:/scratch/node_modules/r-assign/lib'
}

Node.js v23.5.0

@scarf005
Copy link
Contributor Author

scarf005 commented Jan 31, 2025

For exmaple, the first report within this issue is not a bug. The same thing happens in Node:

Well, it works in node but doesn't in Deno. also node version uses CJS.

Second one, not a bug:

same as first one, it runs in node.

@dsherret
Copy link
Member

dsherret commented Jan 31, 2025

That's from a file considered to be commonjs. If you change that file to ESM it won't work (ex. open up a blank project and create a .mjs file and try importing it).

@dsherret dsherret added invalid what appeared to be an issue with Deno wasn't and removed needs triage labels Jan 31, 2025
@dsherret
Copy link
Member

dsherret commented Jan 31, 2025

From what I can tell from a glance, most of these are not issues. It's just how ESM importing CJS works in Node compat/Node. Try putting doing these imports from an .mjs file in Node and I think you'll see the same behaviour as Deno (if not, then please open a specific bug for the specific issue).

  1. Ensure files are imported with extensions and not as directory imports.
  2. Stuff like https://arethetypeswrong.github.io/?p=jointz%407.0.4 has incorrect types. You should see the same kind of export happening in Node. You might need to do a type assertion at the import.

Deno has a bit of incompatibility with TypeScript files in Node projects because TypeScript emits imports/exports as require at runtime, but Deno treats those as esm because they contain imports and exports.

@dsherret
Copy link
Member

The last one does seem like a bug though. I opened #27898 (again, if you notice a difference between Node in .mjs files and Deno with any of these then please let me know. There's a lot in this issue)

@dsherret
Copy link
Member

dsherret commented Jan 31, 2025

Jetschema (wrong types https://arethetypeswrong.github.io/?p=jet-schema%401.4.3):

$ node main.mjs
{ schema: [Function (anonymous)], default: [Function: jetSchema] }
$ deno main.mjs
{ schema: [Function (anonymous)], default: [Function: jetSchema] }

Jointz (wrong types https://arethetypeswrong.github.io/?p=jointz%407.0.4):

$ node main.mjs
{
  Validator: [Getter],
  FailedValidationError: [Getter],
  default: [class jointz]
}
$ deno main.mjs
{
  Validator: [Getter],
  FailedValidationError: [Getter],
  default: [class jointz]
}

Going to close this one, but let me know if I missing something.

@dsherret dsherret closed this as not planned Won't fix, can't repro, duplicate, stale Jan 31, 2025
@Hajime-san
Copy link
Contributor

related #26652

scarf005 added a commit to scarf005/typescript-runtime-type-benchmarks that referenced this issue Jan 31, 2025
skip when deno has compatibility issues with packages: denoland/deno#27894
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid what appeared to be an issue with Deno wasn't node compat
Projects
None yet
Development

No branches or pull requests

4 participants