typeorm: Migration Unexpected token error
Issue type:
[ ] question [x] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[x] postgres
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo
TypeORM version:
[x] latest
[ ] @next
[ ] 0.x.x (or put your version here)
Steps to reproduce or a small repository showing the problem:
I’m having a problem when running typeorm migration:run I’m getting this error:
(function (exports, require, module, __filename, __dirname) { import { Entity, PrimaryGeneratedColumn, Column } from ‘typeorm’;
SyntaxError: Unexpected token {
After reading a few issues people suggested to run: ts-node ./node_modules/.bin/typeorm migration:run, but I’m also getting errors:
basedir=$(dirname “$(echo “$0” | sed -e ‘s,\,/,g’)”) ^^^^^^^ SyntaxError: missing ) after argument list
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 22 (6 by maintainers)
I solved my problem by installing
ts-nodeas a dev dependency:and later by adding script to
package.jsonfile:Now you can invoke any typeorm CLI command in the following way:
Guys, I believe this problem happen when
typeorm migration:runtries to execute.tsfiles. Try to change your ormconfig and specify only.jsfiles in there.I tried that and even changed the script to mine that was working (
ts-node ./node_modules/typeorm/cli.js) and typednpm run typeormwith no lock. the scipt it tries to run ists-node ./node_modules/typeorm/cli.js "migration:generate" "-n" "MigrationName"why put them in quotations ???Update: solved by removing
"esModuleInterop": true,from tsconfig but still, I have to put all script in scripts section I meannpm run typeorm -- migration:generate -n MigrationNametranslated tots-node ./node_modules/typeorm/cli.js "migration:generate" "-n" "MigrationName"thanksI’m using migration with
.tsfiles and it works without any problems.after long I installed ts-node typescript typeorm globally and use
ts-node ./node_modules/typeorm/cli.js migration:generate -n new1command things start to work. Update: I added"esModuleInterop": true,to tsconfig.json.\node_modules\.bin\ts-node ./node_modules/typeorm/cli.js migration:generate -n MigrationNameworked for me. I’ve installed ts-node locally.