Azure / azure-functions-pack

Easily package your Node.js Functions for Azure Functions
MIT License
153 stars 31 forks source link

Dynamic Require Error #78

Open carloseachaves opened 6 years ago

carloseachaves commented 6 years ago

Hi All,

I'm having problem with a dynamic require.

When i did it, work perfect

var sample = require('./sample.json');

module.exports = function (context, req) {
    context.log('JavaScript HTTP trigger function processed a request.');

    if (req.query.name || (req.body && req.body.name)) {
        context.res = {
            // status: 200, /* Defaults to 200 */
            body: "Hello " + (req.query.name || req.body.name)
        };
    }
    else {
        context.res = {
            status: 400,
            body: "Please pass a name on the query string or in the request body"
        };
    }
    context.done();
};

But when i try require a json file with a variables, the funcpack pack ./ command seems work well but when i start az functions dont work well. Could you help me?

var file = './sample.json';
var sample = require(file);

module.exports = function (context, req) {
    context.log('JavaScript HTTP trigger function processed a request.');

    if (req.query.name || (req.body && req.body.name)) {
        context.res = {
            // status: 200, /* Defaults to 200 */
            body: "Hello " + (req.query.name || req.body.name)
        };
    }
    else {
        context.res = {
            status: 400,
            body: "Please pass a name on the query string or in the request body"
        };
    }
    context.done();
};
funcpack pack ./
info: Generating project files/metadata
info: Webpacking project
info: Complete!
func host start
[03/22/2018 20:51:25] Reading host configuration file '/Users/carlos.e.chaves/Documents/XXX/1.75/bla/host.json'
2/2018 20:51:25] Host configuration file read:
[03/22/2018 20:51:25] {}
info: Worker.Node.6d12f6d6-ff1c-42f6-998c-e3c676f25a43[0]
      Start Process: node  --inspect=5858 "/Users/carlos.e.chaves/.nvm/versions/node/v8.6.0/lib/node_modules/azure-functions-core-tools/bin/workers/node/dist/src/nodejsWorker.js" --host 127.0.0.1 --port 57853 --workerId 6d12f6d6-ff1c-42f6-998c-e3c676f25a43 --requestId 0feb311e-f3a7-453d-b94c-6f00f8020571
info: Worker.Node.6d12f6d6-ff1c-42f6-998c-e3c676f25a43[0]
      Debugger listening on ws://127.0.0.1:5858/5d65476e-6351-49f8-b990-8610705ed27e
info: Worker.Node.6d12f6d6-ff1c-42f6-998c-e3c676f25a43[0]
      For help see https://nodejs.org/en/docs/inspector
[03/22/2018 20:51:25] Generating 1 job function(s)
[03/22/2018 20:51:25] Starting Host (HostId=amac02pt7s2g8wp-1297204405, Version=2.0.11415.0, ProcessId=15729, Debug=False, ConsecutiveErrors=0, StartupCount=1, FunctionsExtensionVersion=)
[03/22/2018 20:51:25] Found the following functions:
[03/22/2018 20:51:25] Host.Functions.HttpTriggerJS
[03/22/2018 20:51:25]
[03/22/2018 20:51:25] Job host started
info: Worker.Node.6d12f6d6-ff1c-42f6-998c-e3c676f25a43[0]
      Worker 6d12f6d6-ff1c-42f6-998c-e3c676f25a43 connecting on 127.0.0.1:57853
Listening on http://localhost:7071/
Hit CTRL-C to exit...

Http Functions:

    HttpTriggerJS: http://localhost:7071/api/HttpTriggerJS

info: Worker.Node.6d12f6d6-ff1c-42f6-998c-e3c676f25a43[0]
      Worker was unable to load function HttpTriggerJS: 'Error: Cannot find module "."'
info: Worker.Node.6d12f6d6-ff1c-42f6-998c-e3c676f25a43[0]
      Worker 6d12f6d6-ff1c-42f6-998c-e3c676f25a43 malformed message functionLoadResponse.result.result: string expected
info: Worker.Node.6d12f6d6-ff1c-42f6-998c-e3c676f25a43[0]
      Worker 6d12f6d6-ff1c-42f6-998c-e3c676f25a43 uncaught exception:  functionLoadResponse.result.result: string expected
info: Worker.Node.6d12f6d6-ff1c-42f6-998c-e3c676f25a43[0]
      Worker 6d12f6d6-ff1c-42f6-998c-e3c676f25a43 exited with code 1
fail: Worker.Node.6d12f6d6-ff1c-42f6-998c-e3c676f25a43[0]
      Worker encountered an error.
info: Worker.Node.af1bdde3-6b66-4d9a-92b7-3cb19a766797[0]
      Start Process: node  --inspect=5858 "/Users/carlos.e.chaves/.nvm/versions/node/v8.6.0/lib/node_modules/azure-functions-core-tools/bin/workers/node/dist/src/nodejsWorker.js" --host 127.0.0.1 --port 57853 --workerId af1bdde3-6b66-4d9a-92b7-3cb19a766797 --requestId c3693bf2-ad22-4462-894e-dc1455f237d9
[03/22/2018 20:51:26] A ScriptHost error has occurred
[03/22/2018 20:51:26] Worker process with pid 15730 exited with code 1.
info: Worker.Node.af1bdde3-6b66-4d9a-92b7-3cb19a766797[0]
      Debugger listening on ws://127.0.0.1:5858/efcdd037-49f3-462c-8ab3-befdb13ea971
info: Worker.Node.af1bdde3-6b66-4d9a-92b7-3cb19a766797[0]
      For help see https://nodejs.org/en/docs/inspector
info: Worker.Node.af1bdde3-6b66-4d9a-92b7-3cb19a766797[0]
      Worker af1bdde3-6b66-4d9a-92b7-3cb19a766797 connecting on 127.0.0.1:57853
info: Worker.Node.af1bdde3-6b66-4d9a-92b7-3cb19a766797[0]
      Worker was unable to load function HttpTriggerJS: 'Error: Cannot find module "."'
info: Worker.Node.af1bdde3-6b66-4d9a-92b7-3cb19a766797[0]
      Worker af1bdde3-6b66-4d9a-92b7-3cb19a766797 malformed message functionLoadResponse.result.result: string expected
info: Worker.Node.af1bdde3-6b66-4d9a-92b7-3cb19a766797[0]
      Worker af1bdde3-6b66-4d9a-92b7-3cb19a766797 uncaught exception:  functionLoadResponse.result.result: string expected
info: Worker.Node.af1bdde3-6b66-4d9a-92b7-3cb19a766797[0]
      Worker af1bdde3-6b66-4d9a-92b7-3cb19a766797 exited with code 1
fail: Worker.Node.af1bdde3-6b66-4d9a-92b7-3cb19a766797[0]
      Worker encountered an error.
info: Worker.Node.f7523997-154c-43f9-b5a2-54959a995cfc[0]
      Start Process: node  --inspect=5858 "/Users/carlos.e.chaves/.nvm/versions/node/v8.6.0/lib/node_modules/azure-functions-core-tools/bin/workers/node/dist/src/nodejsWorker.js" --host 127.0.0.1 --port 57853 --workerId f7523997-154c-43f9-b5a2-54959a995cfc --requestId 9e691fb8-9e49-4e98-9c2b-b3ca72a5c45a
[03/22/2018 20:51:26] A ScriptHost error has occurred
[03/22/2018 20:51:26] Worker process with pid 15733 exited with code 1.
info: Worker.Node.f7523997-154c-43f9-b5a2-54959a995cfc[0]
      Debugger listening on ws://127.0.0.1:5858/6ab6398d-ff77-44c9-b510-7bed5c5edaa0
info: Worker.Node.f7523997-154c-43f9-b5a2-54959a995cfc[0]
      For help see https://nodejs.org/en/docs/inspector
info: Worker.Node.f7523997-154c-43f9-b5a2-54959a995cfc[0]
      Worker f7523997-154c-43f9-b5a2-54959a995cfc connecting on 127.0.0.1:57853
info: Worker.Node.f7523997-154c-43f9-b5a2-54959a995cfc[0]
      Worker was unable to load function HttpTriggerJS: 'Error: Cannot find module "."'
info: Worker.Node.f7523997-154c-43f9-b5a2-54959a995cfc[0]
      Worker f7523997-154c-43f9-b5a2-54959a995cfc malformed message functionLoadResponse.result.result: string expected
info: Worker.Node.f7523997-154c-43f9-b5a2-54959a995cfc[0]
      Worker f7523997-154c-43f9-b5a2-54959a995cfc uncaught exception:  functionLoadResponse.result.result: string expected
info: Worker.Node.f7523997-154c-43f9-b5a2-54959a995cfc[0]
      Worker f7523997-154c-43f9-b5a2-54959a995cfc exited with code 1
fail: Worker.Node.f7523997-154c-43f9-b5a2-54959a995cfc[0]
      Worker encountered an error.
[03/22/2018 20:51:26] A ScriptHost error has occurred
[03/22/2018 20:51:26] Worker process with pid 15734 exited with code 1.