2017-09-03 414 views
0

爲什麼不會局部模塊加載時使用雲功能,我發現,對火力地堡雲功能使用package.json文件加載dependencies,但叫我的函數時我得到一個錯誤:的火力地堡

Code in file index.js can't be loaded. 
Did you list all required modules in the package.json dependencies? 
Detailed stack trace: Error: Cannot find module 'express' 
    at Function.Module._resolveFilename (module.js:469:15) 
    at Function.Module._load (module.js:417:25) 
    at Module.require (module.js:497:17) 
    at require (internal/module.js:20:19) 
    at Object.<anonymous> (/user_code/rest_api.js:2:17) 
    at Module._compile (module.js:570:32) 
    at Object.Module._extensions..js (module.js:579:10) 
    at Module.load (module.js:487:32) 
    at tryModuleLoad (module.js:446:12) 
    at Function.Module._load (module.js:438:3) 

這是我index.js文件:

const processor = require('./processor.js'); 

exports.processThing = functions.https.onRequest((req, res) => { 
    let param = req.body.param; 
    processor.process(param); 
}); 

回答

1

你不包括文件擴展名requiring Node modules時。你require應改爲:

const processor = require('./processor'); 

的火力地堡CLI應採取其他的事情。它會捆綁它,就像您的package.json需要的依賴項。