我遇到了已安装的NPM软件包的“找不到模块”错误,并且似乎出现在node_modules文件夹中。基础包本身缺少什么吗?
这是我的package.json:
{
"name": "cmtest",
"version": "0.0.0",
"description": "cmtest",
"main": "server.js",
"author": {
"name": "Andrew"
},
"dependencies": {
"cloudmersive": "^1.3.2"
}
}
然后我打电话给要求:
'use strict';
var http = require('http');
var Cloudmersive = require('cloudmersive');
var port = process.env.PORT || 1337;
http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello World\n');
var api = new Cloudmersive.BarcodeLookupApi()
var value = "value_example"; // {String} Barcode value
var callback = function (error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
api.barcodeLookupEanLookup(value, callback);
}).listen(port);
但我收到此错误:
"Cannot find module 'cloudmersive'"
"Error: Cannot find module 'cloudmersive'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:571:15)
at Function.Module._load (internal/modules/cjs/loader.js:497:25)
at Module.require (internal/modules/cjs/loader.js:626:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous> (c:\users\andrew\documents\visual studio 2017\Projects\cmtest\cmtest\server.js:3:20)
at Module._compile (internal/modules/cjs/loader.js:675:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
at Module.load (internal/modules/cjs/loader.js:589:32)
at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
at Function.Module._load (internal/modules/cjs/loader.js:520:3)"
有任何想法吗?包装本身有问题吗?我这是开发/配置问题吗?
软件包cloudmersive随NPM一起安装,并显示在node_modules文件夹中。我还尝试使用nvm在多个不同版本之间切换。
底层软件包源在这里:https://github.com/Cloudmersive/Cloudmersive.APIClient.Javascript
index.js文件有问题吗?
最佳答案
Cloudmersive的package.json
表示main是src/client.invoker/index.js
,但文件不在该目录中。
关于node.js - 找不到Node.js模块,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50186738/