Skip to content

Remove "module" field from package.json to fix webpack compatibility #1587

@azu

Description

@azu

Problem

Webpack breaks when both type=commonjs and module field exist simultaneously in package.json.
Currently, textlint has this mixed configuration which causes issues.

Related to: textlint/editor#108

Due to Node.js 20's backport of require(esm), there are cases where it breaks without explicit specification.
Reference: #1474

textlint being type=commonjs is intentional, and there are plans to migrate to type=module in the future.
For now, we should ensure that type=commonjs and module field don't coexist.

Proposed Solution

  • Remove the module field from textlint's package.json

Workaround

For webpack users, this issue can be avoided by configuring webpack to ignore the "module" field.
Conversely, if the "module" field is not ignored, it will break.

Reference: https://webpack.js.org/configuration/resolve/#resolveimportsfields

resolve: {
    fallback: {
        fs: false
    },
    // "module" field should be ignored
    // type=commonjs and "module" field is not compatible
    mainFields: ["browser", "main"]
},

e.g.

Expected Behavior

After removing the module field, webpack should be able to properly resolve textlint without requiring additional configuration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions