vinejs / vine

VineJS is a form data validation library for Node.js
https://vinejs.dev
MIT License
1.1k stars 21 forks source link

require() of ES Module #34

Closed maicolbruski closed 9 months ago

maicolbruski commented 9 months ago

Package version

^1.7.1

Describe the bug

Hi, I tried to install vinejs but a receive this error

/Users/maicolbruski/Documents/www/commerce/admin-api/node_modules/ts-node/dist/index.js:851
            return old(m, filename);
                   ^
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/maicolbruski/Documents/www/commerce/admin-api/node_modules/@vinejs/vine/build/index.js from /Users/maicolbruski/Documents/www/commerce/admin-api/src/domain/brand/brand-route.ts not supported.
Instead change the require of index.js in /Users/maicolbruski/Documents/www/commerce/admin-api/src/domain/brand/brand-route.ts to a dynamic import() which is available in all CommonJS modules.
    at require.extensions.<computed> [as .js] (/Users/maicolbruski/Documents/www/commerce/admin-api/node_modules/ts-node/dist/index.js:851:20)
    at Object.<anonymous> (/Users/maicolbruski/Documents/www/commerce/admin-api/src/domain/brand/brand-route.ts:42:30)
    at m._compile (/Users/maicolbruski/Documents/www/commerce/admin-api/node_modules/ts-node/dist/index.js:857:29) {
  code: 'ERR_REQUIRE_ESM'
}
[nodemon] app crashed - waiting for file changes before starting...

My Project:

Typescript Project.

node -v v20.11.1

{
  "compilerOptions": {
    "target": "es5",
    "module": "CommonJS",
    "lib": ["es6"],
    "allowJs": true,
    "outDir": "build",
    "rootDir": "src",
    "strict": true,
    "noImplicitAny": false,
    "esModuleInterop": true,
    "resolveJsonModule": true,
    "declaration": true,
    "typeRoots": [
      "./src/types",
      "./index.d.ts"
    ]
  },
  "include": [
    "./src/types",
    "./index.d.ts",
  ],
}

Reproduction repo

No response

Julien-R44 commented 9 months ago

As mentioned here: https://vinejs.dev/docs/getting_started

Vine is an ESM only library. So you'll need to move your application to ES modules. According to your tsconfig, you're compiling to CommonJS

AlanGreyjoy commented 4 months ago

durrrrrrr i UsE EsM oN a BaCkEnD