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

[Bug]: SyntaxError: Named export 'ComponentLoader' not found. The requested module 'adminjs' is a CommonJS module #1605

Open
jmaric opened this issue Jan 15, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@jmaric
Copy link

jmaric commented Jan 15, 2024

Contact Details

No response

What happened?

i have implemented Adminjs in my Nodejs app and when i run it locally it works as expected, but when i try to upload it to Railway server i get:

SyntaxError: Named export 'ComponentLoader' not found. The requested module 'adminjs' is a CommonJS module, which may not support all module.exports as named exports.

Bug prevalence

whenever i upload to Railway server

AdminJS dependencies version

"@adminjs/design-system": "^4.0.3",
"@adminjs/express": "^6.0.1",
"@adminjs/sequelize": "^4.0.0",
"adminjs": "^7.5.2",

What browsers do you see the problem on?

No response

Relevant log output

import { ComponentLoader } from 'adminjs'
^^^^^^^^^^^^^^^
SyntaxError: Named export 'ComponentLoader' not found. The requested module 'adminjs' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'adminjs';
const { ComponentLoader } = pkg;

Relevant code that's giving you issues

import { fileURLToPath } from 'url';
import { ComponentLoader } from 'adminjs'

const componentLoader = new ComponentLoader();

const Components = {
    MyDashboard: componentLoader.add('MyDashboard', fileURLToPath(new URL('./components/dashboard.jsx', import.meta.url))),
    // other custom components
}



export { componentLoader, Components }
@jmaric jmaric added the bug Something isn't working label Jan 15, 2024
@dziraf
Copy link
Contributor

dziraf commented Jan 19, 2024

It looks to be a Railway integration issue of some kind since we haven't had similar issues with other hosting services. Especially this error:

The requested module 'adminjs' is a CommonJS module, which may not support all module.exports as named exports.

All latest versions of AJS are ESM-only and there's no CJS code in it's releases. My guess is that Railway runs your code through some kind of wrapper that's written in CommonJS.

@jmaric
Copy link
Author

jmaric commented Jan 28, 2024

i ve had same issue with Heroku and Google console...

@dziraf
Copy link
Contributor

dziraf commented Mar 21, 2024

Could you share your tsconfig if it's a Typescript app?

@jmaric
Copy link
Author

jmaric commented Mar 21, 2024 via email

@dziraf
Copy link
Contributor

dziraf commented Mar 21, 2024

Do you use Babel or any other JS compiler?

Could you try to import everything from adminjs and show the log output?

import * as AdminJSModule from 'adminjs'

console.log(AdminJSModule)

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

No branches or pull requests

2 participants