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.

CLI broken in ES modules due to `cosmiconfig-typescript-loader`

See original GitHub issue

Describe the bug

The programmatic CLI usage in ES modules appears to be broken, this might be due in part to kamilkisiela/graphql-config#1069 by @Codex- as the error occurs with cosmiconfig-typescript-loader/dist/esm/index.js which is the package of subject in the aforementioned PR.

It’s also worth mentioning that simply importing anything from @graphql-codegen/cli in an ES module triggers this crash.

@dotansimha @B2o5T Any insight here would be highly appreciated, This is a roadblock for me.

Error

(node:70003) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
/home/diizzayy/dev/gqlbug/node_modules/cosmiconfig-typescript-loader/dist/esm/index.js:1
import { TypeScriptLoader } from "./loader";
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1033:15)
    at Module._compile (node:internal/modules/cjs/loader:1069:27)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:170:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
error Command failed with exit code 1.

Your Example Website or App

https://github.com/Diizzayy/codegen-es-bug

Steps to Reproduce the Bug or Issue

I’ve produced a basic reproduction

simply run yarn install followed by yarn start

Expected behavior

the graphql-codegen CLI should properly generate a file called gql.ts

Screenshots or Videos

No response

Platform


  • Operating System: Linux
  • Node Version: v16.15.1
  • Package Manager: yarn@1.22.18
  • @graphql-codegen/cli: ^2.11.2
  • @graphql-codegen/typescript: ^2.7.2
  • graphql: ^16.5.0

Codegen Config File

No response

Additional context

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Diizzayycommented, Jul 29, 2022

@B2o5T @Codex- I can confirm it’s been resolved by your changes.

1reaction
Codex-commented, Jul 29, 2022

I have already made the PR on graphql-config 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues · EndemolShineGroup/cosmiconfig-typescript-loader
A TypeScript loader for Cosmiconfig. Contribute to EndemolShineGroup/cosmiconfig-typescript-loader development by creating an account on GitHub.
Read more >
Dependencies | @backstage/cli | npm - Open Source Insights
arrow_right @babel/core. 7.20.5 Notes Version 7.20.5 Published November 28... arrow_right @babel/plugin‑transform‑modules‑commonjs. 7.19.6 Notes Version 7.19.6 Published October 20, 20...
Read more >
cosmiconfig-typescript-loader - npm
Start using cosmiconfig-typescript-loader in your project by running ... const moduleName = "module"; const explorer = cosmiconfig("test", ...
Read more >
Migrate from v4 - Vue CLI
npm install -g @vue/cli # OR yarn global add @vue/cli ... css-loader is upgraded from v3 to v6, a few CSS Module related...
Read more >
Open Source Used In Socio 1.0 - Cisco
1.8 endemolshinegroup/cosmiconfig-typescript-loader 3.0.2 ... 1.1378 es-module-lexer 0.9.3 ... 1.2370 babel-helper-split-export-declaration 7.0.0.
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