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

[Error] When use 'api init' Error: Module did not self-register #61

Closed
c0ncentus opened this issue Feb 13, 2020 · 6 comments
Closed

[Error] When use 'api init' Error: Module did not self-register #61

c0ncentus opened this issue Feb 13, 2020 · 6 comments
Assignees

Comments

@c0ncentus
Copy link

c0ncentus commented Feb 13, 2020

Hi,

  1. I make "npm install @useoptic/cli -g"
  2. api init
    I follow step by step the doc https://docs.useoptic.com/ but its produce error when type "api init"

Env
npm 6.13.7
@useoptic/cli/7.0.5 win32-x64 node-v13.6.0

project dependency :
"dependencies": {
"@types/express": "^4.17.2",
"@types/node": "^13.7.1",
"express": "^4.17.1"
}

import * as express from 'express';
// tslint:disable-next-line: no-duplicate-imports

const app = express();

app.get('/', (req: any, res: any) => { res.json({ test: 'Api is alive !' }); });
app.get('/Test', (req: any, res: any) => { res.json({ exTest: 'Expected this !' }); });

app.listen(3000, () => { console.log('My API is running...'); });

export default app;

When use api init its produce this:

    at Object.<anonymous> (C:/Users/Martin/AppData/Roaming/npm/node_modules/@useoptic/cli/node_modules/registry-js/dist/lib/registry.js:4:7)

There are other requirements for launching api init ?

@lvenier
Copy link

lvenier commented Feb 13, 2020

@c0ncentus : I did use that link to set it up :
https://dashboard.useoptic.com/setup/express-js

The main change is
app.listen(process.env.OPTIC_API_PORT || process.env.PORT)
in your case :
app.listen(process.env.OPTIC_API_PORT || 3000)

I see you have

app.listen(3000, () => { console.log('My API is running...'); });

in your code example.

Hope it helps.

@devdoshi
Copy link
Contributor

Hi @c0ncentus - The api init command doesn't start your server so I suspect it's something else, but you will eventually need to make the changes above (thanks @lvenier!).

It looks like you are running on Windows, which we have not tested rigorously. I am planning to get a Windows setup for testing soon, but in the meantime, if you continue to run into issues could you record a screencast so we can see all the steps and complete error messages?

@c0ncentus
Copy link
Author

I will see later if I have another trouble ^^
depend on effort / simple of reproduce and what happened.

@c0ncentus
Copy link
Author

c0ncentus commented Feb 13, 2020

import * as express from 'express';
// tslint:disable-next-line: no-duplicate-imports

const app = express();

app.get('/', (req: any, res: any) => { res.json({ test: 'Api is alive !' }); });
app.get('/Test', (req: any, res: any) => { res.json({ exTest: 'Expected this !' }); });

app.listen(process.env.OPTIC_API_PORT || 3000, () => { console.log('My API is running...'); });

export default app;

still the same issue

there it is : https://github.com/c0ncentus/test_Optic (the repo)

@devdoshi
Copy link
Contributor

@c0ncentus thanks for the additional info!

When you run api init Optic doesn't know about your code yet. api init is the command that asks you questions so that it can learn how to run your code when you run the api start command. If you are having issues running api init, then it is most likely an installation issue.

Based on the original error message you shared:

Error: Module did not self-register    at Object.<anonymous> (C:/Users/Martin/AppData/Roaming/npm/node_modules/@useoptic/cli/node_modules/registry-js/dist/lib/registry.js:4:7)

it seems like the failure is that one of our dependencies is not working. The most likely cause is upgrading your node version without rebuilding Optic.

Can you npm uninstall and reinstall @useoptic/cli and let me know if you still run into the issue? I can not replicate your issue on the latest node 13 on Mac, so it would help to see exactly what you are seeing in the terminal when you install and run api init.

@c0ncentus
Copy link
Author

npm uninstall -g @useoptic/cli
npm install -g @useoptic/cli

[ .................] - fetchMetadata: sill resolveWithNewModule node-fetch@2.6.0 checking installable status[ .................] | fetchMetadata: sill resolveWithNewModule 
[ .................] \ fetchMetadata: sill resolveWithNewModule 
npm WARN deprecated core-js@2.6.11: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
C:\Users\Martin\AppData\Roaming\npm\api -> C:\Users\Martin\AppData\Roaming\npm\node_modules\@useoptic\cli\bin\run

> registry-js@1.9.0 install C:\Users\Martin\AppData\Roaming\npm\node_modules\@useoptic\cli\node_modules\registry-js
> prebuild-install || node-gyp rebuild

prebuild-install WARN install No prebuilt binaries found (target=13.6.0 runtime=node arch=x64 libc= platform=win32)

C:\Users\Martin\AppData\Roaming\npm\node_modules\@useoptic\cli\node_modules\registry-js>if not defined npm_config_node_gyp (node "C:\Users\Martin\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "C:\Users\Martin\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
Les projets sont générés individuellement dans cette solution. Pour activer la génération en parallèle, ajoutez le commutateur "/m".
  main.cc
  win_delay_load_hook.cc
     CrÚation de la bibliothÞque C:\Users\Martin\AppData\Roaming\npm\node_modules\@useoptic\cli\node_modules\registry-js\build\Relea
  se\registry.lib et de l'objet C:\Users\Martin\AppData\Roaming\npm\node_modules\@useoptic\cli\node_modules\registry-js\build\Releas
  e\registry.exp
  registry.vcxproj -> C:\Users\Martin\AppData\Roaming\npm\node_modules\@useoptic\cli\node_modules\registry-js\build\Release\\registr
  y.node

> win-version-info@3.0.1 install C:\Users\Martin\AppData\Roaming\npm\node_modules\@useoptic\cli\node_modules\win-version-info
> node skip.js || prebuild-install || node-gyp rebuild

prebuild-install WARN install No prebuilt binaries found (target=13.6.0 runtime=node arch=x64 libc= platform=win32)

C:\Users\Martin\AppData\Roaming\npm\node_modules\@useoptic\cli\node_modules\win-version-info>if not defined npm_config_node_gyp (node "C:\Users\Martin\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "C:\Users\Martin\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
Les projets sont générés individuellement dans cette solution. Pour activer la génération en parallèle, ajoutez le commutateur "/m".
  VersionInfo.cc
  showver.cc
  win_delay_load_hook.cc
     CrÚation de la bibliothÞque C:\Users\Martin\AppData\Roaming\npm\node_modules\@useoptic\cli\node_modules\win-version-info\build\
  Release\VersionInfo.lib et de l'objet C:\Users\Martin\AppData\Roaming\npm\node_modules\@useoptic\cli\node_modules\win-version-info
  \build\Release\VersionInfo.exp
  VersionInfo.vcxproj -> C:\Users\Martin\AppData\Roaming\npm\node_modules\@useoptic\cli\node_modules\win-version-info\build\Release\
  \VersionInfo.node

> core-js@2.6.11 postinstall C:\Users\Martin\AppData\Roaming\npm\node_modules\@useoptic\cli\node_modules\core-js
> node -e "try{require('./postinstall')}catch(e){}"

[lot of things ....]

thats weird but it work :)

However i change many times the node version before the install of optic cli : o

thanks for help 👍

notnmeyer pushed a commit that referenced this issue Aug 3, 2022
* Implement getting github context

* Type out the event in context

* Change loading from env variable to file load

* Add comment to check run behavior

* fmt
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

3 participants