Skip to content
This repository has been archived by the owner on Jul 19, 2024. It is now read-only.

Dynamic Require Error #78

Open
carloseachaves opened this issue Mar 22, 2018 · 0 comments
Open

Dynamic Require Error #78

carloseachaves opened this issue Mar 22, 2018 · 0 comments

Comments

@carloseachaves
Copy link

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.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant