simenandre / nestjs-envalid

Simple wrapper on top of envalid for NestJS
Apache License 2.0
25 stars 1 forks source link

v2.1.1 broke import #19

Closed HazirBot closed 1 year ago

HazirBot commented 1 year ago

getting this error when trying to npm run

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: projectPath\node_modules\nestjs-envalid\dist\src\plugin.js
require() of ES modules is not supported.
require() of projectPath\node_modules\nestjs-envalid\dist\src\plugin.js from projectPath\dist\env\env.config.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope a
s ES modules.
Instead rename plugin.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from projectPath\node_modules\nestjs-envalid\package.json.
simenandre commented 1 year ago

Hello!

Thank you for opening this issue. This likely caused by not using ESM.

To continue using this package, you either have to upgrade to ESM or use v1. We still support v1 btw, but new features will be added to v2.

You can read more here: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

HazirBot commented 1 year ago

sure, might wanna throw that in the readme.md

feel free to close issue as done

simenandre commented 1 year ago

Hello @HazirBot,

I've updated the README to show this now. What do you think?

Btw, just released a new version on v1 for to include support for nestjs v10 along with a new NPM tag. To install updates for CommonJS (not ESM), you can use this command:

yarn add nestjs-envalid@legacy envalid