jjangga0214 / hasura-cli

Hasura CLI as an npm package
https://www.npmjs.com/package/hasura-cli
90 stars 27 forks source link

Error exporting metadata #72

Open bernatvadell opened 2 years ago

bernatvadell commented 2 years ago

Hi!

Im trying to configure hasura console to manage migrations.

I've tested the binary for linux and the npm package, but the error is the same.

npx hasura-cli metadata export
FATA[0000] failed to export metadata: cannot export actions from metadata: error parsing metadata 
object: actions
file: actions.yaml
error: error in converting metadata to sdl: exit status 1: internal/modules/package_json_reader.js:4
const internalModuleReadJSON = function (f) { return require('fs').internalModuleReadJSON(f); };
                                                                   ^

TypeError: require(...).internalModuleReadJSON is not a function
    at internalModuleReadJSON (internal/modules/package_json_reader.js:4:68)
    at Object.read (internal/modules/package_json_reader.js:19:34)
    at readPackage (internal/modules/cjs/loader.js:237:36)
    at readPackageScope (internal/modules/cjs/loader.js:270:19)
    at trySelf (internal/modules/cjs/loader.js:386:40)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:793:24)
    at Function.Module._load (internal/modules/cjs/loader.js:667:27)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at Module._preloadModules (internal/modules/cjs/loader.js:1147:12)
    at loadPreloadModules (internal/bootstrap/pre_execution.js:451:5) 

Enviroment

jrobber commented 2 years ago

@bernatvadell I get this exact same error, but only if I run it in VSCode. If I use WindowsTerminal to open my Ubuntu shell and run it from there, it works.

jjangga0214 commented 2 years ago

@bernatvadell @jrobber Hi! Thank you for reporting the issue! May I ask if this happens with the latest version? (I personally don't use/have a Windows machine (though I may be able to use VM if necessary), so I'd like you to test if possible)

Thanks!

jjangga0214 commented 2 years ago

I am also curious whether npx hasura-cli metadata export and npx hasura metadata export can have different results.

I 'guess', theoretically, some of these scenarios may be possible. (I don't know if CLI can be executed both on WSL and Windows regardless of how it was installed.)

@bernatvadell @jrobber Would you advise which are possible and which you can test?

Thanks!

jjangga0214 commented 2 years ago

@jrobber

I get this exact same error, but only if I run it in VSCode. If I use WindowsTerminal to open my Ubuntu shell and run it from there, it works.

Maybe, that's because VSCode changes the environment, like by adding NODE_OPTIONS or so. Let me know if you know/find some information!

maksimovicdanijel commented 1 year ago

I had the same issue with applying metadata to the GraphQL engine when running from VSCode's integrated terminal. When run from the standard macOS terminal it worked fine. I was running Hasura commands from VSCode without any issues just until recently so maybe it's connected to the VSCode version (it automatically installs updates on my machine)?

VSCode version: 1.73.1 Hasura CLI version: 2.6.1

emme1444 commented 1 month ago

Had the same issue. I'm running Visual Studio Code Version 1.91.0.

Disabling Auto Attach works as a workaround for me. To re-enable it, execute the Debug: Toggle Auto Attach command from the Command Palette and set it to whatever it was previously. Choosing Temporarily disable auto attach in this session to disable it temporarily does not work.

Don't forget to relaunch the integrated terminal for the disabling to take effect.

For me Auto Attach being enabled, or temporarily disabled, adds the following to my environment:

$ echo $NODE_OPTIONS
 --require /home/user/.config/Code/User/workspaceStorage/ee7680bfac58bb7fb0b18d6be57f57bb/ms-vscode.js-debug/bootloader.js

Which seems, to me, to be the cause somehow. When Auto Attach is disabled NODE_OPTIONS is empty.

Linux 6.9.7 Hasura CLI: 2.40.2 Node: 22.2.0 VSCode: 1.91.0