_detect_package_hooks throws error with "type": "module" in package.json
See original GitHub issueHello! I believe because the _detect_package_hooks
script is ran in the same context as the package its installed in, it now errors when @zeit/git-hooks
is used in a project that sets type
to module
in its package.json
.
internal/process/esm_loader.js:74
internalBinding('errors').triggerUncaughtException(
^
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension "" for /Scrubbed/project/folder/.git/hooks/_detect_package_hooks
at Loader.defaultGetFormat [as _getFormat] (internal/modules/esm/get_format.js:71:15)
at Loader.getFormat (internal/modules/esm/loader.js:102:42)
at Loader.getModuleJob (internal/modules/esm/loader.js:231:31)
at async Loader.import (internal/modules/esm/loader.js:165:17)
at async Object.loadESM (internal/process/esm_loader.js:68:5) {
code: 'ERR_UNKNOWN_FILE_EXTENSION'
}
When I do not set type
to module
it runs as expected.
I was able to “fix” this locally by forcing that script to be ran as a .cjs
file. This required renaming _detect_package_hooks
to _detect_package_hooks.cjs
and altering the hook (in this case pre-commit
) to call it with that extension. Obviously not the most backward-compatible of fixes, however. (Although we’re very close to v10 being EOL.)
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Why is 'type: module' in package.json file? - Stack Overflow
I upgraded the node and built the existing file. But it didn't build, and there was an error. Error [ERR_REQUIRE_ESM]: Must use import ......
Read more >Add type = "module" in package.json to support nodejs in ...
To make it work, I had to add a main entry to the package.json as well as the "type": "module" (otherwise I just...
Read more >package.json - npm Docs
Description. This document is all you need to know about what's required in your package.json file. It must be actual JSON, not just...
Read more >Modules: Packages | Node.js v19.3.0 Documentation
A package.json "type" value of "module" tells Node.js to interpret .js files ... require('pkg/subpath.js') throws an ERR_PACKAGE_PATH_NOT_EXPORTED error.
Read more >CommonJS vs. ES modules in Node.js - LogRocket Blog
The ES module format is the official standard format to package ... be done by adding a "type: module" field inside the nearest...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sure! I’ll try to take a swing at it this weekend.
Awesome 😃