3

What is the configuration requirements to use import instead of require?

I'm using function runtime v2. I tried upgrading node to v10.12.0 but still get this error when it hits the imports Worker was unable to load function store: 'SyntaxError: Unexpected token {'

I have node version set to 10.12.0 in local.settings and in package.json. my function is setup like this ...

module.exports = async function(context, queueMessage) {
import { cosmos } from "@azure/cosmos";
import { updateChat } from "./channels/chat/newChatMessage";
import { updateAttributeStatus } from 
"./channels/attribute/updateAttributeStatus";
import { documentRequest } from "./channels/document/documentRequest";
...

Which version of node is supported by Azure Functions and is import supported? If so, how do I set it up?

Thanks, Donnie

Donnie Kerr
  • 334
  • 4
  • 18

1 Answers1

3

According to the docs these versions are supported for V2:

Active LTS and Current Node.js versions (8.11.1 and 10.6.0 recommended). Set the version by using the WEBSITE_NODE_DEFAULT_VERSION app setting.

So the node version has to be set in the Application Settings as explained here.

Regarding the use of import vs require, this is still an experimental feature in Node, therefore I don't think it's possible to use this in Azure Functions yet.

I'd probably go with TypeScript instead and transpile it before uploading (you can find some examples on how to get started with that on GitHub).

Thomas
  • 4,030
  • 4
  • 40
  • 79
  • 1
    Thank you Thomas! Guess my error does prove that import is not supported in Azure Functions, even with the --experimental-modules parameter set. I reverted back to commonJS and it works fine, so I guess I'll stay with that for now. – Donnie Kerr Oct 13 '18 at 12:30