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.

ESM package is invalid

See original GitHub issue

Package.json mentions that this is an Node ES module:

https://github.com/fczbkk/css-selector-generator/blob/d72f6ffe61b8874b46b6424d4d5131295712103b/package.json#L8

But ESM requires file extensions, which are missing:

https://github.com/fczbkk/css-selector-generator/blob/d72f6ffe61b8874b46b6424d4d5131295712103b/src/index.ts#L1

Additionally, your . import actually point to the non-ESM version, so it’s doubly-incorrect:

  • import "css-selector-generator"' fails because build/index.js not ESM at all
  • import "css-selector-generator/esm" fails because it’s not a valid node ESM import

Little big note: To have file extensions you’ll have to write .js in your TS imports, even if the file is actually .ts; That’s TypeScript for you.

You might want to at-least-temporarily use this workflow to ensure that your module is importable from the tools you want to support:

https://github.com/fregante/ghatemplates/blob/main/esm-lint/esm-lint.yml

For reference, this is the error Webpack shows when importing /esm directly:

ERROR in ./node_modules/css-selector-generator/esm/index.js 5:0-49
Module not found: Error: Can't resolve './constants' in './node_modules/css-selector-generator/esm'
Did you mean 'constants.js'?
BREAKING CHANGE: The request './constants' failed to resolve only because it was resolved as fully specified
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
fczbkkcommented, Aug 17, 2022

Finally!

1reaction
fregantecommented, Aug 17, 2022

All the issues seems to have been fixed in the package 🎉 I’ll let you know on the next update cycle 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

esm causes optional chaining to be viewed as invalid ...
Use of esm causes optional chaining to be viewed as invalid syntax. Here's an example: import get from 'lodash/fp/get'; const a = {...
Read more >
node.js - How would you fix an 'ERR_REQUIRE_ESM' error?
1)Use fix esm https://www.npmjs.com/package/fix-esm module & import the module like this: const someModule = require("fix-esm"). · 2)Use dynamic ...
Read more >
esm
Getting started. There are two ways to enable esm . Enable esm for packages: Use esm to load the main ES module and...
Read more >
Solved: ESM Firmware Invalid Package Signature
ESM Firmware Invalid Package Signature. I am using OpenManage Essentials to update a newly installed "non-compliant" PowerEdge R510 server.
Read more >
ECMAScript modules | Node.js v19.3.0 Documentation
Throw an Invalid Package Configuration error. Return the parsed JSON source of the file at pjsonURL. Customizing ESM specifier resolution algorithm#. The ...
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