Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert-commonjs-to-esm/exports not working #191

Closed
ngugcx opened this issue Nov 8, 2023 · 8 comments
Closed

convert-commonjs-to-esm/exports not working #191

ngugcx opened this issue Nov 8, 2023 · 8 comments

Comments

@ngugcx
Copy link

ngugcx commented Nov 8, 2023

.putout.json

{
    "rules": {
        "strict-mode/add-missing": "off",
        "package-json/add-type": "off",
        "convert-commonjs-to-esm": "on",
        "remove-console": "off",
        "convert-commonjs-to-esm/require": "on",
        "convert-commonjs-to-esm/commons": "on",
        "convert-commonjs-to-esm/exports": "on",
        "try-catch/sync": "off"
    }
}

lib.js

function test() {
    console.log('test');
}

exports.test = test;

package.json:

{
    "name": "putout-test",
    "version": "1.0.0",
    "type": "module",
    "main": "index.js",
    "license": "MIT"
}

putout lib.js --fix

exports in lib.js is not modified.

putout -v
v32.16.0
@coderaiser
Copy link
Owner

This is not really a good idea to use:

exports.test = test;

Since:

exports = test;

Will just overwrite exports variable, not make any exports.

@ngugcx
Copy link
Author

ngugcx commented Nov 9, 2023

One of third party modules I'm using now uses this way to export.
Can putout handle it?

@coderaiser
Copy link
Owner

coderaiser commented Nov 9, 2023

Yes, just landed a new rule nodejs/convert-exports-to-module-exports. Enable it, and it will do the thing.

@coderaiser
Copy link
Owner

Is it works for you?

@ngugcx
Copy link
Author

ngugcx commented Nov 9, 2023

I want to convert it to es module export.

@coderaiser
Copy link
Owner

Upgrade to v33 and try it, should work for you use case.

@ngugcx
Copy link
Author

ngugcx commented Nov 9, 2023

Tried, lots of plugin not found errors:

No plugin found for a rule: "convert-commonjs-to-esm"
No plugin found for a rule: "convert-commonjs-to-esm/require"

@coderaiser
Copy link
Owner

coderaiser commented Nov 9, 2023

There is no more such plugins (they are merged to @putout/plugin-nodejs), read release notes.
Here is updated config for your use case:

{
    "rules": {
        "strict-mode/add-missing": "off",
        "package-json/add-type": "off",
        "remove-console": "off",
        "nodejs/convert-commonjs-to-esm": "on",
        "try-catch/sync": "off"
    }
}

Is it works for you?

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

No branches or pull requests

2 participants