SoftwareBrothers / adminjs-nestjs

NestJS module to import admin the Nest way
MIT License
158 stars 35 forks source link

`@adminjs/nestjs` is not supporting `swc` builder in NestJs10 #58

Open davvar opened 1 year ago

davvar commented 1 year ago

After changing the builder to swc app stopped working

// nest-cli.json
{
  "$schema": "https://json.schemastore.org/nest-cli",
  "collection": "@nestjs/schematics",
  "sourceRoot": "src",
  "compilerOptions": {
    "deleteOutDir": true,
    "builder": "swc",
    "typeCheck": true
  }
}
[Nest] 23394  - 07/07/2023, 2:06:43 PM   ERROR [ExceptionHandler] No "exports" main defined in /node_modules/@adminjs/nestjs/package.json
Error: No "exports" main defined in /node_modules/@adminjs/nestjs/package.json
    at new NodeError (node:internal/errors:399:5)
    at exportsNotFound (node:internal/modules/esm/resolve:361:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:641:13)
    at resolveExports (node:internal/modules/cjs/loader:565:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:634:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1061:27)
    at Function.Module._load (node:internal/modules/cjs/loader:920:27)
    at Module.require (node:internal/modules/cjs/loader:1141:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at /dist/configs/admin-dashboard/admin-dashboard.module.js:68:84

And this is my module that is simply being imported in app.module.ts

  @Module({
  imports: [
    // AdminJS version 7 is ESM-only. In order to import it, you have to use dynamic imports.
    Promise.all([
      import('@adminjs/nestjs'),
      import('@adminjs/typeorm'),
      import('adminjs'),
    ]).then(
      ([{ AdminModule }, { Database, Resource }, { default: AdminJS }]) => {
        AdminJS.registerAdapter({ Resource, Database });

        return AdminModule.createAdminAsync({
          useFactory: () => ({
            adminJsOptions: {
              rootPath: '/admin',
              resources: [
                // resources
              ],
            },
            sessionOptions: {
              resave: true,
              saveUninitialized: true,
              secret: 'secret',
            },
          }),
        });
      },
    ),
  ],
})
export class AdminDashboardModule {}
rushg171 commented 8 months ago

Facing the same problem. Any solution?

vadolasi commented 6 months ago

Same problem

pacholoamit commented 5 months ago

Same problem here

ArthurRAmaral commented 4 months ago

Same problem here

GeekDenCode commented 3 months ago

I use webpack, but I had exactly the same error.

I used nodenext to solve it, but it didn't help. However, this is still required.

"module": "nodenext",
"moduleResolution": "nodenext"

After many hours, I found a solution. The problem turned out to be that webpack converted dynamic imports into require(), regardless of the module in tsconfig.

Solution:

import(/* webpackIgnore: true */'@adminjs/nestjs')

I hope this helps you in your search for a solution with a swc. Perhaps it has a similar method for saving dynamic imports inside bundle.