[Bug]: SyntaxError: Named export 'ComponentLoader' not found. The requested module 'adminjs' is a CommonJS module
jmaric opened this issue · comments
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 }
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.
i ve had same issue with Heroku and Google console...
Could you share your tsconfig if it's a Typescript app?
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)