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

Error: require() of ES Module node_modules\rsdi\dist\index.js #5

Closed
pedro-lima-reis opened this issue Oct 15, 2023 · 6 comments
Closed

Comments

@pedro-lima-reis
Copy link

I need some help with this:

[ERROR] 01:43:45 Error: require() of ES Module \node_modules\rsdi\dist\index.js from \src\infrastructure\di.ts not supported.
Instead change the require of index.js in \src\infrastructure\di.ts to a dynamic import() which is available in all CommonJS modules.

I updated the version and make all adjustments needed

@radzserg
Copy link
Owner

@pedro-lima-reis what version of node do you use and can you share your package.json file please

@jdiaz-wcslat
Copy link

jdiaz-wcslat commented Oct 24, 2023

@radzserg i have the same problem

nodejs v20.4.0

"devDependencies": { "@commitlint/cli": "^17.7.1", "@commitlint/config-conventional": "^17.7.0", "@types/config": "^3.3.0", "@types/dotenv": "^8.2.0", "@types/express": "^4.17.20", "@types/lodash": "^4.14.195", "@types/node": "^20.4.2", "@typescript-eslint/eslint-plugin": "^6.7.0", "@typescript-eslint/parser": "^6.7.0", "ts-node-dev": "^2.0.0", "tsx": "^3.12.7", "typescript": "^4.9.5" }, "dependencies": { "@typegoose/typegoose": "^11.3.0", "body-parser": "^1.20.1", "config": "^3.3.9", "dotenv": "^16.3.1", "express": "^4.18.2", "rsdi": "^3.0.3", "zod": "^3.21.4" }

@pedro-lima-reis
Copy link
Author

v18.17.1

@paulo123araujo
Copy link

paulo123araujo commented Nov 11, 2023

@pedro-lima-reis did you try to bundle your application to esm and not to commonjs?

A time ago i faced this same kinda of problem, and i solve changing the way my application was built.

just to exemplify, I use these configs:

// tsup.config.ts
import { defineConfig } from 'tsup';

export default defineConfig({
  tsconfig: './tsconfig.json',
  entry: ['./src/**/*.ts'],
  splitting: true,
  sourcemap: true,
  clean: true,
  platform: 'node',
  esbuildOptions(options, _context) {
    // the directory structure will be the same as the source
    options.outbase = './src';
  },
  target: 'node20',
  format: 'esm',
  treeshake: true,
  outDir: 'build',
});
// tsconfig.json
{
    "compilerOptions": {
        "types": ["node"],
        "module": "ESNext",
        "moduleResolution": "Node",
        "target": "ES2020",
        "baseUrl": ".",
        "outDir": "build",
        "esModuleInterop": true,
        "strict": true,
        "resolveJsonModule": true,
        "skipLibCheck": true,
        "sourceMap": true,
        "forceConsistentCasingInFileNames": true,
        "allowJs": true,
        "rootDirs": ["src"],
        "lib": ["DOM", "ESNext"],
        "removeComments": true,
        "paths": {
            "@tests/*": ["./tests/*"],
            "@/*": ["./src/*"]
        },
        "typeRoots": ["./types"],
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "strictPropertyInitialization": false
    },
    "include": ["src", "tests"],
    "exclude": ["node_modules"]
}

and in package.json I set "type": "module", and with all this settings the application worked on production.

Hope it helps.

@radzserg
Copy link
Owner

"type": "module" should do the trick. @jdiaz-wcslat @pedro-lima-reis can you also share your package.json file. Thank you.

@radzserg
Copy link
Owner

I'm closing this issue for now, since we don't have much feedback.

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

4 participants