2

Generated a nodejs-server stub with the online editor from swagger. After installing the packages, I ran npm start and I'm getting the following error:

internal/modules/cjs/loader.js:638
    throw err;
    ^

Error: Cannot find module 'oas3-tools'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/home/user/project/nodejs-server-server-generated/index.js:6:17)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)

The index.js looks like this:

'use strict';

var path = require('path');
var http = require('http');

var oas3Tools = require('oas3-tools');
var serverPort = 8080;

// swaggerRouter configuration
var options = {
    controllers: path.join(__dirname, './controllers')
};

var expressAppConfig = oas3Tools.expressAppConfig(path.join(__dirname, 'api/openapi.yaml'), options);
expressAppConfig.addValidator();
var app = expressAppConfig.getApp();

// Initialize the Swagger middleware
http.createServer(app).listen(serverPort, function () {
    console.log('Your server is listening on port %d (http://localhost:%d)', serverPort, serverPort);
    console.log('Swagger-ui is available on http://localhost:%d/docs', serverPort);
});

Closest thing I've found was this stackoverflow question, but this doesn't solve my specific problem.

The fix from https://github.com/bug-hunters/oas3-tools/issues/17 doesn't work for me.

Ri1a
  • 737
  • 9
  • 26

2 Answers2

2

Pinning the version to 2.0.2 instead of using ^2.0.2 in package.json works. Use this until a new (working) version of https://github.com/bug-hunters/oas3-tools has been released.

From: https://github.com/bug-hunters/oas3-tools/issues/25

EDIT: Has been fixed in 2.1.3 (https://github.com/bug-hunters/oas3-tools/issues/25#issuecomment-720482897)

Ri1a
  • 737
  • 9
  • 26
0
npm install oas3-tools 

Install oas3-tools From the above command and also you need to upgrade your NPM.

Use the following command to upgrade NPM:

npm install -g npm@latest 
Ri1a
  • 737
  • 9
  • 26
Stanley
  • 41
  • 3
  • 1
    Unfortunately, this solution does not solve my problem. Upgraded npm to `6.14.4` and ran the command `npm install oas3-tools`. Still get the same error. – Ri1a Oct 19 '20 at 14:56