Version compatibility issue Azure functions' Node and DirectlineJS es6 exports

拥有回忆 提交于 2019-12-06 14:19:06

Unfortunately it seems like import-export or node-hook doesn't play well with functions / edgejs (the environment we use to run node).

A couple options to try:

  • use babel to transpile es6 to es5 as a part of your deployment process.
  • write your function in typescript (index.ts) which will do import transpilation automatically - though this may fail for module dependencies, I haven't tried it out

You have three options: 1) Write your code using ES5, 2) setup a task runner (gulp/grunt/npm scripts) to convert your ES6+ code to ES5 using Babel, or 3) write your code in Typescript and compile it to ES5 via task runner/npm scripts.

The most straight-forward method would be: in your file importexportwrapper.js use require instead of import.

Example:

var directline = require('botframework-directlinejs');

Babel + Gulp Option

Install: npm install --save-dev gulp gulp-babel

Run:

var gulp = require("gulp");
var babel = require("gulp-babel");

gulp.task("default", function () {
  return gulp.src("src/app.js") // your source files
    .pipe(babel())
    .pipe(gulp.dest("dist")); // your compiled output directory
});

Read more about Azure Functions Node.js versions here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!