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.

7.6.4 ESM build broken

See original GitHub issue

Bug report

  • [✔] I have checked other issues to make sure this is not a duplicate.

Describe the bug

Generated ESM index.js contains the following (which is identical to typings/index.d.ts):

export { IRule } from './types';
export { allow, and, chain, deny, inputRule, not, or, race, rule } from './constructors';
export { shield } from './shield';

with types.js containing:

export {};

Problems here are:

  1. Empty types.js module - no IRule export.
  2. Reference to './types', './constructors', and './shield' - all are missing .js extensions that are required due to relative import rules.
  3. IRule is TypeScript-specific and should not be emitted in the JavaScript file to begin with…

To Reproduce

  1. "type": "module" in package.json file

  2. Import { IRules } from "graphql-shield". (Or pick your favorite export)

  3. This is my GraphQL Schema.

Not required to reproduce the error

  1. This is the invoked query

Not required to reproduce the error.

  1. I use these permissions

Not required to reproduce the error.

  1. This is the error I see
node:internal/errors:478
    ErrorCaptureStackTrace(err);
    ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '.../node_modules/graphql-shield/esm/constructors' imported from .../node_modules/graphql-shield/esm/index.js
    at new NodeError (node:internal/errors:387:5)
    at finalizeResolution (node:internal/modules/esm/resolve:330:11)
    at moduleResolve (node:internal/modules/esm/resolve:907:10)
    at defaultResolve (node:internal/modules/esm/resolve:1115:11)
    at nextResolve (node:internal/modules/esm/loader:163:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:837:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)
    at link (node:internal/modules/esm/module_job:75:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}```

If I add `--es-module-specifier-resolution=node` to the command line, I get:

```bash
(node:7897) ExperimentalWarning: The Node.js specifier resolution flag is experimental. It could change or be removed at any time.
(Use `node --trace-warnings ...` to show where the warning was created)
file://.../node_modules/graphql-shield/esm/index.js:3
export { IRule } from './types';
         ^^^^^
SyntaxError: The requested module './types' does not provide an export named 'IRule'
    at ModuleJob._instantiate (node:internal/modules/esm/module_job:123:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:189:5)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:526:24)
    at async loadESM (node:internal/process/esm_loader:91:5)
    at async handleMainPromise (node:internal/modules/run_main:65:12)

When I keep the node resolution flag but comment out the first line of esm/index.js and run the application, it starts up fine. Without the flag, Node complains about the next module without a .js extension…

Expected behavior

The build process should produce ESM compliant code.

Actual behaviour

See the description above.

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Reactions:2
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
dimatillcommented, Nov 22, 2022

the fix was released in 7.6.5 please feel free to reopen if the issue still exists

0reactions
helmancommented, Nov 17, 2022

I was having the same issue, downgrade it to v7.6.2 works for me it’s the same issue logged in here

Read more comments on GitHub >

github_iconTop Results From Across the Web

D3 packages are incompatible with Node projects that use ...
When CommonJS is imported from ESM, Node treats module.exports as the ... UMD build is still generated for legacy uses (script tags etc)...
Read more >
webpack/webpack - Gitter
I'm using module federation and promised based dynamic remotes (https://webpack.js.org/concepts/module-federation/#promise-based-dynamic-remotes). Everything is ...
Read more >
Error importing Framer Motion v5 in React (with create-react ...
I downgraded the Framer motion version to "4.1.17" by changing the package.json file and running npm install and it works for me.
Read more >
7 Working with file system paths and file URLs on Node.js
In this chapter, we learn how to work with file system paths and file URLs on Node.js. 7.1 Path-related functionality on Node.js #....
Read more >
Upgrading Ember - Issues with Tests - Questions
But for some reason the update and switch from ember-cli-mocha to ember-mocha broke something. The tests run, then launch the browser like ...
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