Skip to content

Invalid .mjs and .cjs extensions #576

Description

@rtritto

.mjs and .cjs extensions for ESM and CJS aren't supported.

Dual package

My related issue: mongodb-js/ejson-shell-parser#157

Steps to reproduce

  • yarn init -y
  • yarn add @preconstruct/cli
  • add in package.json
  "main": "dist/<PROJECT_NAME>.cjs",
  "module": "dist/<PROJECT_NAME>.mjs",
  "exports": {
    "import": "./dist/<PROJECT_NAME>.mjs",
    "require": "./dist/<PROJECT_NAME>.cjs"
  }
  • create an empty src/index.js file
  • yarn preconstruct build
🎁 error <PROJECT_NAME> main field is invalid, found `"dist/<PROJECT_NAME>.cjs"`, expected `"dist/<PROJECT_NAME>.cjs.js"`
🎁 error <PROJECT_NAME> module field is invalid, found `"dist/<PROJECT_NAME>.mjs"`, expected `"dist/<PROJECT_NAME>.esm.js"`
🎁 info Some of the errors above can be fixed automatically by running preconstruct fix
🎁 info If you want to learn more about the above error, check https://preconstruct.tools/errors
🎁 info If the error is not there and you want to learn more about it, open an issue at https://github.com/preconstruct/preconstruct/issues/new
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

<PROJECT_NAME> is field name of package.json

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions