samuelneff / sequelize-auto-ts

Generate Sequelize definition statements and compatible TypeScript definitions from a database schema
MIT License
79 stars 20 forks source link

"Unexpected token import" what version of Node.js does this require? #18

Closed NobleUplift closed 5 years ago

NobleUplift commented 5 years ago

Just wondering what version of Node you use since I'm getting this:

$ node node_modules/sequelize-auto-ts/lib/cli.ts ...
node_modules/sequelize-auto-ts/lib/cli.ts:4
import generator = require("./sequelize-auto-ts");
^^^^^^

SyntaxError: Unexpected token import
    at createScript (vm.js:74:10)
    at Object.runInThisContext (vm.js:116:10)
    at Module._compile (module.js:533:28)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Function.Module.runMain (module.js:605:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:575:3

I'm running Node v8.1.4 and NPM v5.0.3.

NobleUplift commented 5 years ago

I upgraded to Node v10.15.3 and now it's a similar issue.

$ node node_modules/sequelize-auto-ts/lib/cli.ts ...
node_modules/sequelize-auto-ts/lib/cli.ts:4
import generator = require("./sequelize-auto-ts");
       ^^^^^^^^^

SyntaxError: Unexpected identifier
    at new Script (vm.js:80:7)
    at createScript (vm.js:274:10)
    at Object.runInThisContext (vm.js:326:10)
    at Module._compile (internal/modules/cjs/loader.js:664:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
    at startup (internal/bootstrap/node.js:283:19)
samuelneff commented 5 years ago

*.ts are TypeScript files which need to be run through the TypeScript compiler. The generated *.js files are included alongside and can be run directly in Node. This is a very old project that was written for Node 0.12. I haven't tried running it with a recent version of Node or Sequelize.

samuelneff commented 5 years ago

I noticed the readme does incorrectly say to run the .ts file directly. I updated the readme.

NobleUplift commented 5 years ago

Thank you! Yeah, I noticed that I was trying to run a TypeScript file through Node on Friday, but then realized I would have to try transpiling it if I have to run the *.ts file and then I just gave up.

I got tired of not being able to get typehints for my 125 table definitions and passing all my Sequelize objects in as any. Figured I would give this project a shot. It would be a considerable rewrite in my own project so it probably saves me time not trying to get it to work.

Is this related to sequelize-auto, or was it completely written from scratch?