Node.js + browserify - Error: Cannot find module 'cls-bluebird'
Node.js + browserify - Error: Cannot find module 'cls-bluebird'
我正在尝试 运行 在我的浏览器上使用 node.js 模型将这个简单代码 运行 - 使用 browserify。
test2.js:
var gplay = require('google-play-scraper');
function get_vars(){
var keyword = document.getElementById("keyword");
var limit = document.getElementById("limit");
console.log(keyword);
console.log(limit);
get_search_results(keyword, limit);
}
function get_search_results(keyword, limit){
gplay.search({
term: keyword,
num: limit
}).then(console.log, console.log);
}
index.html:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript" src="test2.js"></script>
</head>
<body>
<input type="text" name="keyword" id="keyword" />
<input type="text" name="limit" id="limit">
<button onclick="get_vars();">GO!</button>
</body>
</html>
每当我在 CMD 上 运行 browserify test2.js -o bundle2.js
时,我都会得到这个输出:
Error: Cannot find module 'cls-bluebird' from 'C:\wamp\www\nodetest\node_modules\request-promise\lib'
at C:\Users\banana\AppData\Roaming\npm\node_modules\browserify\node_modules\resolve\lib\async.js:46:17
at process (C:\Users\banana\AppData\Roaming\npm\node_modules\browserify\node_modules\resolve\lib\async.js:173:43)
at ondir (C:\Users\banana\AppData\Roaming\npm\node_modules\browserify\node_modules\resolve\lib\async.js:188:17)
at load (C:\Users\banana\AppData\Roaming\npm\node_modules\browserify\node_modules\resolve\lib\async.js:69:43)
at onex (C:\Users\banana\AppData\Roaming\npm\node_modules\browserify\node_modules\resolve\lib\async.js:92:31)
at C:\Users\banana\AppData\Roaming\npm\node_modules\browserify\node_modules\resolve\lib\async.js:22:47
at FSReqWrap.oncomplete (fs.js:117:15)
已尝试安装 npm install bluebird
但没有任何变化,而且我在任何地方都找不到此错误。
可能是什么问题?
您是否按照以下步骤操作:
npm install --save bluebird
var Promise = require("bluebird");
To enable long stack traces and warnings in node development:
$ NODE_ENV=development node server.js
To enable long stack traces and warnings in node production:
$ BLUEBIRD_DEBUG=1 node server.js
See Environment Variables.
发件人:
http://bluebirdjs.com/docs/install.html
你可以找到类似的错误,不同的命题来解决它:
https://github.com/request/request-promise/issues/91
希望对您有所帮助,
cls-bluebird
被定义为 request-promise
的开发依赖(它又被 google-play-scraper
使用)。
在request-promise
"confuses" Browserify 中使用cls-bluebird
的方式认为它是一个常规依赖项,因此它试图将它包含在生成的包中。但是因为在 npm install PACKAGE
期间通常不会安装开发依赖项,所以它丢失了,您会收到有关缺少模块的错误消息。
最简单的解决方案是手动安装 cls-bluebird
:
$ npm i cls-bluebird
这允许 Browserify 找到它。如果您有自己的 package.json
.
,则可以添加 --save
或者,您可以安装 google-play-scraper
以及所有开发依赖项:
$ npm i google-play-scraper --dev
但是,这将为 all google-play-scraper
所依赖的模块安装 all 开发依赖项,这使得安装需要很长时间。
我正在尝试 运行 在我的浏览器上使用 node.js 模型将这个简单代码 运行 - 使用 browserify。
test2.js:
var gplay = require('google-play-scraper');
function get_vars(){
var keyword = document.getElementById("keyword");
var limit = document.getElementById("limit");
console.log(keyword);
console.log(limit);
get_search_results(keyword, limit);
}
function get_search_results(keyword, limit){
gplay.search({
term: keyword,
num: limit
}).then(console.log, console.log);
}
index.html:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript" src="test2.js"></script>
</head>
<body>
<input type="text" name="keyword" id="keyword" />
<input type="text" name="limit" id="limit">
<button onclick="get_vars();">GO!</button>
</body>
</html>
每当我在 CMD 上 运行 browserify test2.js -o bundle2.js
时,我都会得到这个输出:
Error: Cannot find module 'cls-bluebird' from 'C:\wamp\www\nodetest\node_modules\request-promise\lib'
at C:\Users\banana\AppData\Roaming\npm\node_modules\browserify\node_modules\resolve\lib\async.js:46:17
at process (C:\Users\banana\AppData\Roaming\npm\node_modules\browserify\node_modules\resolve\lib\async.js:173:43)
at ondir (C:\Users\banana\AppData\Roaming\npm\node_modules\browserify\node_modules\resolve\lib\async.js:188:17)
at load (C:\Users\banana\AppData\Roaming\npm\node_modules\browserify\node_modules\resolve\lib\async.js:69:43)
at onex (C:\Users\banana\AppData\Roaming\npm\node_modules\browserify\node_modules\resolve\lib\async.js:92:31)
at C:\Users\banana\AppData\Roaming\npm\node_modules\browserify\node_modules\resolve\lib\async.js:22:47
at FSReqWrap.oncomplete (fs.js:117:15)
已尝试安装 npm install bluebird
但没有任何变化,而且我在任何地方都找不到此错误。
可能是什么问题?
您是否按照以下步骤操作:
npm install --save bluebird
var Promise = require("bluebird");
To enable long stack traces and warnings in node development:
$ NODE_ENV=development node server.js
To enable long stack traces and warnings in node production:
$ BLUEBIRD_DEBUG=1 node server.js
See Environment Variables.
发件人:
http://bluebirdjs.com/docs/install.html
你可以找到类似的错误,不同的命题来解决它:
https://github.com/request/request-promise/issues/91
希望对您有所帮助,
cls-bluebird
被定义为 request-promise
的开发依赖(它又被 google-play-scraper
使用)。
在request-promise
"confuses" Browserify 中使用cls-bluebird
的方式认为它是一个常规依赖项,因此它试图将它包含在生成的包中。但是因为在 npm install PACKAGE
期间通常不会安装开发依赖项,所以它丢失了,您会收到有关缺少模块的错误消息。
最简单的解决方案是手动安装 cls-bluebird
:
$ npm i cls-bluebird
这允许 Browserify 找到它。如果您有自己的 package.json
.
--save
或者,您可以安装 google-play-scraper
以及所有开发依赖项:
$ npm i google-play-scraper --dev
但是,这将为 all google-play-scraper
所依赖的模块安装 all 开发依赖项,这使得安装需要很长时间。