我已安装模块type
:
~\Documents\appname $ npm ls type
serverless-commerce@5.0.0 C:\Users\user\Documents\appname
`-- type@0.0.3
但是require
找不到它:
~\Documents\appname $ node
> require('type')
{ Error: Cannot find module 'type'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
at Function.Module._load (internal/modules/cjs/loader.js:506:25)
at Module.require (internal/modules/cjs/loader.js:636:17)
at require (internal/modules/cjs/helpers.js:20:18) code: 'MODULE_NOT_FOUND' }
我该如何解决?
答案 0 :(得分:0)
您需要程序包在module.paths
中查找。可能没有正确的路径C:\Users\user\Documents\appname
。
您是:
require('.type')
require('C:\Users\user\Documents\appname\type')
答案 1 :(得分:0)
在这种情况下,问题是由a badly formed package通过以下方式创建的:
index.js
main
entry in package.json
来指定替代项。将"main": "checks.js",
行添加到package.json
可使模块正常工作
node
> require('type')
{ isBoolean: [Function: isBoolean],
isUndefined: [Function: isUndefined],
isNull: [Function: isNull],
isString: [Function: isString],
isNumber: [Function: isNumber],
isObject: [Function: isObject],
instanceOf: [Function: instanceOf],
isRegExp: [Function: isRegExp],
isDate: [Function: isDate],
isFunction: [Function: isFunction],
isArray: [Function: isArray],
isArguments: [Function: isArguments],
isPrimitive: [Function: isPrimitive],
isFlat: [Function: isFlat],
isEmpty: [Function: isEmpty],
isJSON: [Function] }
>