muratgozel / turkey-neighbourhoods

Always up to date names of cities, districts and neighbourhoods of Turkey + city distances. / Her zaman güncel, Türkiye şehir, posta kodu, plaka kodu, ilçe ve mahalle listesi + şehirlerarası mesafeler.
MIT License
55 stars 9 forks source link

ESM not-supported error on v3 #9

Closed Kolahzary closed 1 year ago

Kolahzary commented 1 year ago

I'm trying to use turkey-neighbourhoods@v3 in a nx monorepo with the default tsconfig

> nx run my-app-name:serve:development

node:internal/errors:490
    ErrorCaptureStackTrace(err);
    ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /path-to-repo/node_modules/.pnpm/turkey-neighbourhoods@3.0.8/node_modules/turkey-neighbourhoods/dist/turkey-neighbourhoods.cjs.js not supported.
turkey-neighbourhoods.cjs.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead rename turkey-neighbourhoods.cjs.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /path-to-repo/node_modules/.pnpm/turkey-neighbourhoods@3.0.8/node_modules/turkey-neighbourhoods/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

    at Module._load (/path-to-repo/node_modules/.pnpm/@nx+js@16.2.2_@swc+core@1.3.51_nx@16.2.2_typescript@5.0.4/node_modules/@nx/js/src/executors/node/node-with-require-overrides.js:18:31)
    at Object.defineProperty.value (/path-to-repo/dist/apps/my-app-name/main.js:6252:18)
    at __webpack_require__ (/path-to-repo/dist/apps/my-app-name/main.js:6448:41)
    at Array.<anonymous> (/path-to-repo/dist/apps/my-app-name/main.js:6211:33)
    at __webpack_require__ (/path-to-repo/dist/apps/my-app-name/main.js:6448:41)
    at Object.defineProperty.value (/path-to-repo/dist/apps/my-app-name/main.js:5734:28)
    at __webpack_require__ (/path-to-repo/dist/apps/my-app-name/main.js:6448:41)
    at Object.defineProperty.value (/path-to-repo/dist/apps/my-app-name/main.js:5408:48)
    at __webpack_require__ (/path-to-repo/dist/apps/my-app-name/main.js:6448:41)
    at Object.defineProperty.value (/path-to-repo/dist/apps/my-app-name/main.js:5390:22)
    at __webpack_require__ (/path-to-repo/dist/apps/my-app-name/main.js:6448:41)
    at Object.defineProperty.value (/path-to-repo/dist/apps/my-app-name/main.js:3796:30)
    at __webpack_require__ (/path-to-repo/dist/apps/my-app-name/main.js:6448:41)
    at Object.defineProperty.value (/path-to-repo/dist/apps/my-app-name/main.js:3719:28)
    at __webpack_require__ (/path-to-repo/dist/apps/my-app-name/main.js:6448:41)
    at Object.defineProperty.value (/path-to-repo/dist/apps/my-app-name/main.js:1530:31)
    at __webpack_require__ (/path-to-repo/dist/apps/my-app-name/main.js:6448:41)
    at Object.defineProperty.value (/path-to-repo/dist/apps/my-app-name/main.js:1513:22)
    at __webpack_require__ (/path-to-repo/dist/apps/my-app-name/main.js:6448:41)
    at Object.defineProperty.value (/path-to-repo/dist/apps/my-app-name/main.js:412:20)
    at __webpack_require__ (/path-to-repo/dist/apps/my-app-name/main.js:6448:41)
    at Array.<anonymous> (/path-to-repo/dist/apps/my-app-name/main.js:14:22)
    at __webpack_require__ (/path-to-repo/dist/apps/my-app-name/main.js:6448:41)
    at /path-to-repo/dist/apps/my-app-name/main.js:6475:37
    at Object.<anonymous> (/path-to-repo/dist/apps/my-app-name/main.js:6480:12)
    at Module._load (/path-to-repo/node_modules/.pnpm/@nx+js@16.2.2_@swc+core@1.3.51_nx@16.2.2_typescript@5.0.4/node_modules/@nx/js/src/executors/node/node-with-require-overrides.js:10:31) {
  code: 'ERR_REQUIRE_ESM'
}

Node.js v18.15.0
muratgozel commented 1 year ago

Hey @Kolahzary I have updated the library to fix this error. Could you check if everything is okay please?

Kolahzary commented 1 year ago

Thanks for your commit @muratgozel, It's fixed and works perfectly, this issue can be closed