Closed sethreidnz closed 8 years ago
why are you executing a .map file? can you provide more information?
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!
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.
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.
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.
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!
Glad this got resolved.
Just had a very similar problem - same scenario-, I'm glad I found this issue! Helped me sort it out.
Any chance someone got a reference to a solution? his link is broken.
Sorry man this was ages ago I cannot even remember what the issue was...
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.
I'm using node and express and when I build certain files then I get this error:
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