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

7.6.4 ESM build broken #1487

Closed
smallstepstoday opened this issue Nov 8, 2022 · 5 comments
Closed

7.6.4 ESM build broken #1487

smallstepstoday opened this issue Nov 8, 2022 · 5 comments

Comments

@smallstepstoday
Copy link

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.

@alienbuild
Copy link

Surprised this isn't a more prominent issue. Any known work around for this ?

@Ivanfvj
Copy link

Ivanfvj commented Nov 11, 2022

We had the same issue and we solve it this way:

graphql-shield: 7.5.0 (fixed dependency, without the ^)
graphql-middleware: ^4.0.1 (another suggestion is the one below, fixed 6.0.9)

think it's connected with maticzav/graphql-middleware#433 and you can downgrade graphql-middleware to =6.0.9 to make it work.

@hyusetiawan
Copy link

having the same problem, the 7.5.0 works , graphql-middleware can be the latest, just make sure to do the following when applying the middleware:

const _schema = makeSchema(...
export const schema = applyMiddleware(_schema, permissions.generate(_schema))

@helman
Copy link

helman commented 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

@dimatill
Copy link
Collaborator

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

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

6 participants