question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

_detect_package_hooks throws error with "type": "module" in package.json

See original GitHub issue

Hello! 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:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rdmurphycommented, Jan 15, 2021

Sure! I’ll try to take a swing at it this weekend.

0reactions
Qix-commented, Jan 15, 2021

Awesome 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found