jfromaniello/url-join

Error [ERR_REQUIRE_ESM]: require() of ES Module

Closed this issue · 7 comments

failed to use url-join in a typescript project.( Here I am in a nestJS project)

image

I think the error is pretty descriptive here, you cannot require() an ES module in whatever build tool you are using. I'd follow the recommendation and use a dynamic import instead.

Hi @raphaelsoul I'm also having this problem with NestJS. I guess the easiest option now is to downgrade to previous release. I've been looking for a possibility of migrating to ESM but the tooling aren't there yet. ESLint import rules for example still complains about .js extension on TypeScript project which is mandatory for ESM. Also adding .js extension on TypeScript project seems counter intuitive in my opinion.

Just downgrade to v4.0.1.

Just downgrade to v4.0.1.

Yep, definitely downgraded after some considerations. I've already tried converting my project into full ESM, the result is that it won't even run. ReflectMetadata for example have a lot of problem with it, so is other dependencies. Not that I don't want to but it's not feasible as of now. A lot of tooling and dependencies getting broken with ESM.

Just downgrade to v4.0.1.

Yep, definitely downgraded after some considerations. I've already tried converting my project into full ESM, the result is that it won't even run. ReflectMetadata for example have a lot of problem with it, so is other dependencies. Not that I don't want to but it's not feasible as of now. A lot of tooling and dependencies getting broken with ESM.

I think this is how JS ecosystem works, a fucked-up but prosperous mess.

Looks like the authors of NestJS have expressed that they have no interest in implementing support for loading pure ES modules (see nestjs/nest#7021 (comment)). This was over a year ago so perhaps this opinion has changed.

Either way this is an issue with NestJS, so I'd recommend you log an issue there. The more people ask for it the more likely it will be implemented.

I have created a package called url-join-dual, to which I've added exports for CommonJS.