Skip to content

--disallow-code-generation-from-strings breaks nest's named ESM exports #10846

Closed
@ephys

Description

@ephys

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

If you run node with the --disallow-code-generation-from-strings option & use native ESM imports, some named ESM imports break.

Minimum reproduction code

https://github.com/ephys/nest-esm-issue

Steps to reproduce

  1. npm ci
  2. node index.mjs # should run without issues
  3. node --disallow-code-generation-from-strings index.mjs # should break: named import not found

Expected behavior

For named exports to be available even when --disallow-code-generation-from-strings is used

Package

I've only tested the first 4 packages of this list, only @nestjs/core succeeded (but it's possible one of the imports is failing. This issue is likely relevant to all packages):

  • I don't know. Or some 3rd-party package
  • @nestjs/common
  • @nestjs/core
  • @nestjs/microservices
  • @nestjs/platform-express
  • @nestjs/platform-fastify
  • @nestjs/platform-socket.io
  • @nestjs/platform-ws
  • @nestjs/testing
  • @nestjs/websockets
  • Other (see below)

Other package

No response

NestJS version

9.2.1

Packages versions

"@nestjs/core": "^9.2.1",
"@nestjs/common": "^9.2.1",
"@nestjs/microservices": "^9.2.1",
"@nestjs/platform-express": "^9.2.1",

Node.js version

18.13.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

I think this can be fixed by including an ESM export map file, like I've done in other projects here: https://github.com/sequelize/sequelize/blob/main/src/decorators/legacy/index.mjs (+ test to ensure it stays up to date)

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs triageThis issue has not been looked into

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions