Skip to content

Cannot use as an ES module #232

@zoriya

Description

@zoriya

Right now, inline-style-prefixer cannot be used as an esmodule in node. The module field of the package.json is never read by node (ref) and manually importing inline-style-prefixer/es does not work either since:

  • "type": "module" is not defined on the package.json so we can't use the "import" syntax
  • imports don't contain file extensions (as in import createPrefixer from './createPrefixer.js' instead of import createPrefixer from './createPrefixer'), which is required by the esm specification (ref)

To fix this, we could:

  • use a babel plugin to add file extensions for the esm build, something like: babel-plugin-add-import-extension
  • add "type": "module" to the package.json
  • add a exports field in package.json to ask node to include the esm version "imports" call and keep the cjs version on "require"

I have not written a PR yet for that because I fear adding the exports field might be a breaking change. I wonder if we should use something like nodejs/help#3993 (comment)

I also wonder if keeping a cjs version is still relevant today, or if an esmodule is enough.

For context on why I want an ES module, you can see necolas/react-native-web#2668 or vikejs/vike#1637 (reply in thread)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions