Skip to content

resolveAppScriptPath() is not pass scriptExtensions to fixFileExtensions() #246

@ebbnormal

Description

@ebbnormal

When working with the following middleware/ directory structure:

middleware / 
   verison.js
   version.js.map

when we run the server, loopback tries to execute the file with the extension .map as if it were a middleware factory with a .js extension.

Here is the stack trace which is produced when running the loopback server.

/Users/server/build/middleware/version.js.map:1
(function (exports, require, module, __filename, __dirname) { {"version":3,"file":"version.js","sourceRoot":"/Users/angular2-loopback-starter/server/src/","sources":["middleware/version.ts"],"names":[],"mappings":";AAAA,+CAAsC;AACtC,IAAI,UAAU,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC,OAAO,CAAC;AAE1D,IAAI,UAAU,GAAG,IAAI,CAAC;AAEtB,oBAAI,CAAC,4BAA4B,EAAE,UAAC,KAAK,EAAE,MAAM,EAAE,MAAM;IACvD,UAAU,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC;AAC7B,CAAC,CAAC,CAAC;AAEH,iBAAS;IACP,MAAM,CAAC,UAAC,GAAG,EAAE,GAAG,EAAE,IAAI;QACpB,GAAG,CAAC,MAAM,CAAC,WAAW,EAAE,UAAU,GAAG,IAAI,GAAG,UAAU,GAAG,GAAG,CAAC,CAAC;QAC9D,IAAI,EAAE,CAAC;IACT,CAAC,CAAC;AACJ,CAAC,CAAC"}
                                                                        ^
SyntaxError: Unexpected token :
    at Object.exports.runInThisContext (vm.js:76:16)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at /Users/node_modules/loopback-boot/lib/executor.js:343:19
    at Array.forEach (native)
    at setupMiddleware (/Users/node_modules/loopback-boot/lib/executor.js:340:14)
    at execute (/Users/node_modules/loopback-boot/lib/executor.js:40:3)
    at bootLoopBackApp (/Users/node_modules/loopback-boot/index.js:154:3)
    at Object.<anonymous> (/Users/server/build/server.js:7:1)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)

We tried to do a workaround by including the new options variable to boot() by adding the scriptExtensions [".js"]. We thought this would exclude the .map file being executed in the middleware directory. However, when we debugged it, we saw that the scriptExtensions was undefined at the moment of filtering out files based on extensions. We traced this back to fixFileExtensions not received the options.scriptExtensions.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions