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

Module not importable #234

Open
mia-pi-git opened this issue Mar 28, 2022 · 0 comments
Open

Module not importable #234

mia-pi-git opened this issue Mar 28, 2022 · 0 comments

Comments

@mia-pi-git
Copy link

mia-pi-git commented Mar 28, 2022

Hi! This is a really cool project you have here and I'd love to use it.
However, when I install it, it crashes upon use.
When I try to require() it in CJS, I get:

> require('./vendordeps/jsonm')
Uncaught:
Error [ERR_REQUIRE_ESM]: require() of ES Module ~/projects/project/jsonm/dist/index.cjs.js not supported.
index.cjs.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead rename index.cjs.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in ~/projects/project/vendordeps/jsonm/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

When I try to import() it in ESM, I get:

> import('./vendordeps/jsonm')
Promise {
  <pending>,
  [Symbol(async_id_symbol)]: 113,
  [Symbol(trigger_async_id_symbol)]: 5,
  [Symbol(destroyed)]: { destroyed: false }
}
> Uncaught:
Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '~/projects/project/vendordeps/jsonm' is not supported resolving ES modules imported from ~/projects/project/repl
Did you mean to import ../vendordeps/jsonm/dist/index.cjs.js?

After fiddling with module types and package.json a bit, it also indicates promisie has the same build issue.
This seems to occur on all versions.
My suggested fix would be removing "type": "module" from package.json in this package, @jsonstack/model and promisie. I can confirm through testing that this fixes the first issue.
After that, there's an error in the built CJS file.

Uncaught TypeError: Object prototype may only be an Object or null: undefined
    at Function.create (<anonymous>)
    at Object.inherits (~/projects/ai-stuff/vendordeps/jsonm/dist/index.cjs.js:47792:29)
    at Object.<anonymous> (~/projects/ai-stuff/vendordeps/jsonm/dist/index.cjs.js:50626:8)

If I can help, please let me know.
Have a nice day!

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

1 participant