ไม่พบโมดูล 'oas3-tools'

Oct 19 2020

สร้างโหนดเซิร์ฟเวอร์ nodejs กับตัวแก้ไขออนไลน์จาก swagger หลังจากติดตั้งแพคเกจฉันวิ่งnpm startและได้รับข้อผิดพลาดต่อไปนี้:

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)

index.jsลักษณะเช่นนี้

'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);
});

สิ่งที่ใกล้เคียงที่ฉันได้พบเป็นนี้คำถาม StackOverflow แต่นี้ไม่ได้แก้ปัญหาเฉพาะของฉัน

การแก้ไขจาก https://github.com/bug-hunters/oas3-tools/issues/17 ไม่ได้ผลสำหรับฉัน

คำตอบ

1 Ri1a Oct 19 2020 at 22:05

การตรึงเวอร์ชันไว้2.0.2แทนที่จะใช้^2.0.2ในpackage.jsonผลงาน ใช้สิ่งนี้จนถึงเวอร์ชัน (ใช้งานได้) ใหม่ของhttps://github.com/bug-hunters/oas3-tools ได้รับการเผยแพร่แล้ว

จาก: https://github.com/bug-hunters/oas3-tools/issues/25

แก้ไข : ได้รับการแก้ไขใน2.1.3(https://github.com/bug-hunters/oas3-tools/issues/25#issuecomment-720482897)

Stanley Oct 19 2020 at 21:48
npm install oas3-tools 

ติดตั้ง oas3-tools จากคำสั่งด้านบนและคุณต้องอัพเกรด NPM ของคุณด้วย

ใช้คำสั่งต่อไปนี้เพื่ออัพเกรด NPM:

npm install -g npm@latest