sindresorhus/query-string

Error on compile NESTJS

angelopedroso opened this issue · 2 comments

I'm using the latest nestjs version, and when I start application it's returns that error:

const query_string_1 = require("query-string");
                       ^
Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\user\Desktop\cielo\cielo-api\node_modules\.pnpm\query-string@9.0.0\node_modules\query-string\index.js from C:\Users\user\Desktop\cielo\cielo-api\dist\modules\cielo\controllers\pedido\pedido.controller.js not supported.
Instead change the require of index.js in C:\Users\user\Desktop\cielo\cielo-api\dist\modules\cielo\controllers\pedido\pedido.controller.js to a dynamic import() which is available in all CommonJS modules.  
    at Object.<anonymous> (C:\Users\user\Desktop\cielo\cielo-api\dist\modules\cielo\controllers\pedido\pedido.controller.js:20:24)

import:

import querystring from 'query-string';

ts.config:

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "ES2021",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "skipLibCheck": true,
    "strictNullChecks": false,
    "noImplicitAny": false,
    "strictBindCallApply": false,
    "forceConsistentCasingInFileNames": false,
    "noFallthroughCasesInSwitch": false
  }
}

https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#how-can-i-make-my-typescript-project-output-esm

but why would you force end-users to output esm? it's not standard for .js to use import

switching to qs which works out of the box