migration:generate throws a SyntaxError with clean project template
See original GitHub issueIssue type:
[ ] question [x] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[x] mysql
/ mariadb
[ ] oracle
[ ] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo
TypeORM version:
[ ] latest
[ ] @next
[x] 0.2.20
(or put your version here)
typeorm migration:generate
throws a SyntaxError
when you run it on a brand new project generated by typeorm init
.
Steps to reproduce or a small repository showing the problem:
I set up a MySQL database (version 5.6) in a Docker container so that it was accessible via the default configuration in ormconfig.json
. Then I did the following:
$ npx typeorm init
$ npm install
$ npx typeorm migration:generate -n User
This was the result:
Error during migration generation:
…/src/entity/User.ts:1
import {Entity, PrimaryGeneratedColumn, Column} from "typeorm";
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Module._compile (internal/modules/cjs/loader.js:892:18)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
at Module.load (internal/modules/cjs/loader.js:812:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14)
at Module.require (internal/modules/cjs/loader.js:849:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Function.PlatformTools.load (…/node_modules/typeorm/platform/PlatformTools.js:109:28)
at /media/evan.sheehan/workshop/tmp/typeorm_template/node_modules/typeorm/util/DirectoryExportedClassesLoader.js:39:69
at Array.map (<anonymous>)
at Object.importClassesFromDirectories (…/node_modules/typeorm/util/DirectoryExportedClassesLoader.js:39:10)
I would expect that, having changed nothing in the project template, I should be able to generate a migration for the User entity.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:14
- Comments:11 (1 by maintainers)
@darthmall That is the recommended way according to https://typeorm.io/#/migrations/running-and-reverting-migrations
I like to add a script to my package.json:
tsconfig.ts-node.json for reference:
and from that point, I run the typeorm cli using
yarn typeorm migration:generate -n User
I had the same issue and after looking through it a bit it seems you have to change the
ormconfig.json
and changeto
Of course then running
npm run start
might not work as expected and you’ll have to change that fromts-node
to just usenode
and have a build step before and that seems to work.Not sure if that’s working as intended or is a bug…