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

New Node.js ESM support ? #727

Closed
fraxken opened this issue May 16, 2020 · 1 comment
Closed

New Node.js ESM support ? #727

fraxken opened this issue May 16, 2020 · 1 comment

Comments

@fraxken
Copy link

fraxken commented May 16, 2020

Hi,

Is there is way for Husky to work with the new native ESM support of Node.js ? I'm working on a Node.js monitoring agent where we use Node ESM but husky stop working because of the type: "module" in the package.json (i guess).

Doc for Node.js ESM: https://nodejs.org/api/esm.html

$ git commit -m "fix: remove nsecure-result"
husky > commit-msg (node v14.2.0)
F:\Code\SlimIO\Core\node_modules\@commitlint\cli\lib\cli.js:124
        throw err;
        ^

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: F:\Code\SlimIO\Core\commitlint.config.js
require() of ES modules is not supported.
require() of F:\Code\SlimIO\Core\commitlint.config.js from F:\Code\SlimIO\Core\node_modules\cosmiconfig\node_modules\import-fresh\index.js is an ES module file as it is a .js file whose nearest parent package.jso
n contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename commitlint.config.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from F:\Code\SlimIO\Core\package.json.

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1192:13)
    at Module.load (internal/modules/cjs/loader.js:1040:32)
    at Function.Module._load (internal/modules/cjs/loader.js:929:14)
    at Module.require (internal/modules/cjs/loader.js:1080:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at module.exports (F:\Code\SlimIO\Core\node_modules\cosmiconfig\node_modules\import-fresh\index.js:28:9)
    at loadJs (F:\Code\SlimIO\Core\node_modules\cosmiconfig\dist\loaders.js:9:18)
    at Explorer.loadFileContent (F:\Code\SlimIO\Core\node_modules\cosmiconfig\dist\createExplorer.js:230:12)
    at F:\Code\SlimIO\Core\node_modules\cosmiconfig\dist\createExplorer.js:252:21 {
  code: 'ERR_REQUIRE_ESM'
}
husky > commit-msg hook failed (add --no-verify to bypass)

I tried a lot of things but nothing work so far.

Repo example: https://github.com/SlimIO/core

Best Regards,
Thomas

@thasmo
Copy link

thasmo commented Jul 10, 2020

Same issue here. Using node 12 and husky in a type: module package and when running npm install I get this error:

Must use import to load ES Module: C:\Users\username\Projects\project\husky.config.js
require() of ES modules is not supported.
require() of C:\Users\username\Projects\project\husky.config.js from C:\Users\username\Projects\project\node_modules\cosmiconfig\dist\loaders.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename husky.config.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from C:\Users\username\Projects\project\package.json.
husky > Failed to install

Not sure if this is a cosmiconfig issue in the first place?! There's an open issue regarding mjs and cjs files as well.

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

No branches or pull requests

3 participants