question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Runtime fails to find the function entry points when code is built with typescript

See original GitHub issue

If the basic JS example code is tweaked to use the azure-functions-typescript typings the local runtime fails with errors and Azure gives a 500.

A ScriptHost error has occurred
[19/08/2017 15:55:42] Exception while executing function: Functions.test. mscorlib: Unable to determine function entry point. If multiple functions are exported, you must indicat
e the entry point, either by naming it 'run' or 'index', or by naming it explicitly via the 'entryPoint' metadata property.

From TS

/* 231 */
/***/ (function(module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function index(context, req) {
...
/***/ (function(module, exports, __webpack_require__) {
module.exports = {
    "test": __webpack_require__(231)
}

From JS

/* 0 */
/***/ (function(module, exports) {
module.exports = function(context, req) {
...
/***/ (function(module, exports, __webpack_require__) {
module.exports = {
    "test": __webpack_require__(0)
}

The webpack_require definition is the same in both, but the import ordinal is different

The TS generated JS is different to the sample with a prefix and postscript added. both related to exports

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function index(context, req) {
... same code as sample
}
exports.index = index;

Hopefully is just a matter of finding the correct module exports format for TS. It’s not clear why webpack behaves differently.

Anyone have good knowledge here?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

15reactions
SteveALeecommented, Aug 20, 2017

The answer turns out to be simple, use the export = form in typescript which resolves to module.exports =

eg

export = function index(context: HttpContext, req: IFunctionRequest): void {

6reactions
michaelbromleycommented, May 9, 2018

In addition to the solution from @SteveALee, I also had to set my Webpack config (using Webpack 4.8.1) to use: libraryTarget: 'commonjs2', which creates an output file with module.exports = ... rather than just exports = ... (See explanation here: https://github.com/webpack/webpack/issues/1114)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to determine function entry point - azure - Stack Overflow
Made two very inconsequential code changes and pushed on Friday and no I'm getting: Exception while executing function: Functions.messages.
Read more >
Azure Functions + Node.js + TypeScript + Webpack
[error] Worker was unable to load function QueueTrigger: 'Unable to determine function entry point. If multiple functions are exported, you must ...
Read more >
Documentation - Module Resolution - TypeScript
Module resolution is the process the compiler uses to figure out what an import refers to. Consider an import statement like import {...
Read more >
Documentation - The Basics - TypeScript
When we run our code, the way that our JavaScript runtime chooses what to do is by figuring out the type of the...
Read more >
Documentation - ECMAScript Modules in Node.js - TypeScript
This code works in CommonJS modules, but will fail in ES modules because relative import paths need to use extensions. As a result,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found