Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected token in map file (node) #5649

Closed
sethreidnz opened this Issue Nov 13, 2015 · 11 comments

Comments

Projects
None yet
5 participants
@sethreidnz
Copy link

sethreidnz commented Nov 13, 2015

I'm using node and express and when I build certain files then I get this error:

error: uncaughtException: c:\dev\pp\PropertyPlot\server\models\index.js.map:1
ction (exports, require, module, __filename, __dirname) { {"version":3,"file":
                                                                    ^
Unexpected token : 

This makes the app break and not work.. I don't really know what the issue is as there is nothing special about the file and it has happened on other files before. Have you seen this issue before? At this point the only option I have is to change the file back to being a .js file and not use typescript there. I am compiling using grunt-ts task but I don't think that is the issue... I could be wrong.

Versions:
Typescript : 1.6.2
Node: v0.12.2

@mhegazy

This comment has been minimized.

Copy link
Contributor

mhegazy commented Nov 13, 2015

why are you executing a .map file? can you provide more information?

@sethreidnz

This comment has been minimized.

Copy link
Author

sethreidnz commented Nov 13, 2015

Sure.

Basically I have an express application that I have just recently converted to use TS and some specific files for example this file

var fs = require("fs");
var path = require("path");
var Sequelize = require("sequelize");
var env = process.env.NODE_ENV || "development";
var sequelize = new Sequelize('propertyplotsql-local', 'sa', '@&KtFvkQK0a6xPnr', {
    host: 'ASUS-PC',
    dialect: 'mssql',
    port: 51622,
    pool: {
        max: 5,
        min: 0,
        idle: 10000
    },
});

class dbContext{
    sequelize: any;
    Sequelize: any;
};

var db = new dbContext();

fs.readdirSync(__dirname)
    .filter(function (file) {
    return (file.indexOf(".") !== 0) && (file !== "index.js");
})
    .forEach(function (file) {
    var model = sequelize.import(path.join(__dirname, file));
    db[model.name] = model;
});

Object.keys(db).forEach(function (modelName) {
    if ("associate" in db[modelName]) {
        db[modelName].associate(db);
    }
});

db.sequelize = sequelize;
db.Sequelize = Sequelize;
module.exports = db;

When compiles creates a .js.map file that is being run presumably by node when the app is running (for debugging using VSCode). The Mapp file looks liek this:

{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":["dbContext","dbContext.constructor"],"mappings":"AAAA,IAAI,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AACvB,IAAI,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAC3B,IAAI,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;AACrC,IAAI,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,aAAa,CAAC;AAChD,IAAI,SAAS,GAAG,IAAI,SAAS,CAAC,uBAAuB,EAAE,IAAI,EAAE,kBAAkB,EAAE;IAC7E,IAAI,EAAE,SAAS;IACf,OAAO,EAAE,OAAO;IAChB,IAAI,EAAE,KAAK;IACX,IAAI,EAAE;QACF,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,CAAC;QACN,IAAI,EAAE,KAAK;KACd;CACJ,CAAC,CAAC;AAEH;IAAAA;IAGAC,CAACA;IAADD,gBAACA;AAADA,CAACA,AAHD,IAGC;AAAA,CAAC;AAEF,IAAI,EAAE,GAAG,IAAI,SAAS,EAAE,CAAC;AAEzB,EAAE,CAAC,WAAW,CAAC,SAAS,CAAC;KACpB,MAAM,CAAC,UAAU,IAAI;IACtB,MAAM,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC;AAC9D,CAAC,CAAC;KACG,OAAO,CAAC,UAAU,IAAI;IACvB,IAAI,KAAK,GAAG,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC;IACzD,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;AAC3B,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,SAAS;IACvC,EAAE,CAAC,CAAC,WAAW,IAAI,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QAC/B,EAAE,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IAChC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,EAAE,CAAC,SAAS,GAAG,SAAS,CAAC;AACzB,EAAE,CAAC,SAAS,GAAG,SAAS,CAAC;AACzB,MAAM,CAAC,OAAO,GAAG,EAAE,CAAC"}

As far as I can tell there is little difference between thsi map file and any other map file in the project and I have map files being created for everything...

What specific further information do you need? This is the debug stack trace:

Running "express:dev" (express) task
Stopping Express server
Starting background Express server
Debugger listening on port 5858
error: uncaughtException: c:\dev\pp\PropertyPlot\server\models\index.js.map:1
ction (exports, require, module, __filename, __dirname) { {"version":3,"file":
                                                                    ^
Unexpected token : date=Fri Nov 13 2015 18:54:33 GMT+1300 (New Zealand Daylight Time), pid=15960, uid=null, gid=null, cwd=c:\dev\pp\PropertyPlot, execPath=C:\Program Files\nodejs\node.exe, version=v0.12.2, argv=[C:\Program Files\nodejs\\node.exe, c:\dev\pp\PropertyPlot\server\app.js], rss=71385088, heapTotal=59714560, heapUsed=26413504, loadavg=[0, 0, 0], uptime=29166.3080866, trace=[column=16, file=vm.js, function=exports.runInThisContext, line=73, method=runInThisContext, native=false, column=25, file=module.js, function=Module._compile, line=443, method=_compile, native=false, column=10, file=module.js, function=Object.Module._extensions..js, line=478, method=Module._extensions..js, native=false, column=32, file=module.js, function=Module.load, line=355, method=load, native=false, column=12, file=module.js, function=Function.Module._load, line=310, method=Module._load, native=false, column=17, file=module.js, function=Module.require, line=365, method=require, native=false, column=17, file=module.js, function=require, line=384, method=null, native=false, column=61, file=c:\dev\pp\PropertyPlot\node_modules\sequelize\lib\sequelize.js, function=Sequelize.import, line=636, method=import, native=false, column=33, file=c:\dev\pp\PropertyPlot\server\models\index.js, function=null, line=27, method=null, native=false, column=null, file=null, function=Array.forEach, line=null, method=forEach, native=true, column=6, file=c:\dev\pp\PropertyPlot\server\models\index.js, function=, line=26, method=null, native=false, column=26, file=module.js, function=Module._compile, line=460, method=_compile, native=false, column=10, file=module.js, function=Object.Module._extensions..js, line=478, method=Module._extensions..js, native=false, column=32, file=module.js, function=Module.load, line=355, method=load, native=false, column=12, file=module.js, function=Function.Module._load, line=310, method=Module._load, native=false, column=17, file=module.js, function=Module.require, line=365, method=require, native=false, column=17, file=module.js, function=require, line=384, method=null, native=false, column=14, file=c:\dev\pp\PropertyPlot\server\app.js, function=, line=12, method=null, native=false, column=26, file=module.js, function=Module._compile, line=460, method=_compile, native=false, column=10, file=module.js, function=Object.Module._extensions..js, line=478, method=Module._extensions..js, native=false, column=32, file=module.js, function=Module.load, line=355, method=load, native=false, column=12, file=module.js, function=Function.Module._load, line=310, method=Module._load, native=false], stack=[c:\dev\pp\PropertyPlot\server\models\index.js.map:1, ction (exports, require, module, __filename, __dirname) { {"version":3,"file":,
                                                                  ^, SyntaxError: Unexpected token :,     at exports.runInThisContext (vm.js:73:16),     at Module._compile (module.js:443:25),     at Object.Module._extensions..js (module.js:478:10),     at Module.load (module.js:355:32),     at Function.Module._load (module.js:310:12),     at Module.require (module.js:365:17),     at require (module.js:384:17),     at Sequelize.import (c:\dev\pp\PropertyPlot\node_modules\sequelize\lib\sequelize.js:636:61),     at c:\dev\pp\PropertyPlot\server\models\index.js:27:33,
at Array.forEach (native),     at Object.<anonymous> (c:\dev\pp\PropertyPlot\server\models\index.js:26:6),     at Module._compile (module.js:460:26),     at Object.Module._extensions..js (module.js:478:10),     at Module.load (module.js:355:32),     at Function.Module._load (module.js:310:12),     at Module.require (module.js:365:17),     at require (module.js:384:17),     at Object.<anonymous> (c:\dev\pp\PropertyPlot\server\app.js:12:14),     at Module._compile (module.js:460:26),     at Object.Module._extensions..js (module.js:478:10),     at Module.load (module.js:355:32),     at Function.Module._load (module.js:310:12)]

Sorry I'm not sure what else I can really provide without giving you access to the code. If you can't figure it out I will try to reproduce with a simple version of what I am doing.

Thanks for you help!

@mhegazy

This comment has been minimized.

Copy link
Contributor

mhegazy commented Nov 13, 2015

the .map files are used by the debugger, they are not executable. the file you should pass to node is your .js file, just like you would without typescript.

the .js file has a comment at the bottom that tells the debugger about the .map file. the debugger then loads the .map file.

you can find more information about source maps at: http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/

if you do not want to have source maps generated, do not pass the --sourceMap flag to the compiler.

@mhegazy mhegazy added the Question label Nov 13, 2015

@sethreidnz

This comment has been minimized.

Copy link
Author

sethreidnz commented Nov 13, 2015

Yes i understand how it works and i do want the map file so i can debug. Howver this error occurs when just including the index.js file generated from the above index.ts file. I am not manually including the map file. That is, as far as i can tell, node throwing an error when trying to intepret the map file.

I cant see anyway in my code that the map file is being included i am including the index.js from my app.js with

Var model = require ('./models/index')

I will try to repoduce in a simple repo tomorrow.

@mhegazy

This comment has been minimized.

Copy link
Contributor

mhegazy commented Nov 13, 2015

this sounds strange. i can not reproduce this with the input files you provided above. these must be something else going on. would love to take a look if you can provide more information.

@mhegazy mhegazy added Needs More Info and removed Question labels Nov 13, 2015

@sethreidnz

This comment has been minimized.

Copy link
Author

sethreidnz commented Nov 14, 2015

My apologies! after trying to reproduce I discovered what the issue was. Due to the implementation in the code above I was i fact executing the map file as you said. Therefore it was throwing an error. I have fixed this now because I was doing some file reading and I needed to exclude the .map AND the .ts files from the results.

Thanks for you help! If you would like to see what I am talking about I have created a repo here which I might flesh out more when I have time showing people how to create a Sequelize structure for your files using ts:

https://github.com/justsayno/express-example

Its very basic and doesn't really use any Typescript yet but shows how you would change their code to not break like it did for me.

Once again this had nothing to do with Typescript and my apologies!

@mhegazy mhegazy closed this Nov 14, 2015

@mhegazy

This comment has been minimized.

Copy link
Contributor

mhegazy commented Nov 14, 2015

Glad this got resolved.

@wkrueger

This comment has been minimized.

Copy link

wkrueger commented Jul 22, 2016

Just had a very similar problem - same scenario-, I'm glad I found this issue!
Helped me sort it out.

@gviligvili

This comment has been minimized.

Copy link

gviligvili commented Jan 12, 2018

Any chance someone got a reference to a solution? his link is broken.

@sethreidnz

This comment has been minimized.

Copy link
Author

sethreidnz commented Jan 13, 2018

Sorry man this was ages ago I cannot even remember what the issue was...

@jwigley

This comment has been minimized.

Copy link

jwigley commented Jun 1, 2018

I ran into this today, so I thought I'd share the answer for future typescript/sequelize migrators!

Most likely you followed a fairly common Sequelize code example which load all models from a directory, without checking explicitly for *.js files in that directory. Instead, it's requiring the yourmodel.js.map file and causing the error.

@Microsoft Microsoft locked and limited conversation to collaborators Jul 31, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.