-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
Migration cli unexpected token import #371
Comments
you node environment tries to load |
did you resolve your issue? |
Yes. Thankyou.
…On Sat, Apr 1, 2017 at 6:08 PM, Umed Khudoiberdiev ***@***.*** > wrote:
did you resolve your issue?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#371 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AF_TKcft41bhrW4f-mWjrq-DFLsynzyiks5rrjA0gaJpZM4MpUiq>
.
|
@adithep how did you resolve the issue? |
Anyone wondering about this, you must run your .ts files thru ts-node first. Simply:
|
Hi @stormpat, thanks for the hint. Still is not working for me.
gives me still:
Any idea ? |
@davidmpaz try to setup your tsconfig properly - try to set target to es5 |
Hi @pleerock , thanks for answering. These are my current config files tsconfig.json: {
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"skipLibCheck": true,
"noStrictGenericChecks": true,
"lib": [
"dom",
"es2015"
],
"module": "es2015",
"moduleResolution": "node",
"sourceMap": true,
"target": "es5"
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules"
],
"compileOnSave": false,
"atom": {
"rewriteTsconfig": false
}
} ormconfig.json {
"type": "sqlite",
"database": "./products.db",
"synchronize": true,
"logging": false,
"entities": [
"src/models/**/*.ts"
],
"migrations": [
"src/migration/**/*.ts"
],
"subscribers": [
"src/subscriber/**/*.ts"
],
"cli": {
"entitiesDir": "src/models",
"migrationsDir": "src/migration",
"subscribersDir": "src/subscriber"
}
} package.json deps: "dependencies": {
"@angular/common": "4.1.3",
"@angular/core": "4.1.3",
"@angular/forms": "4.1.3",
"@angular/http": "4.1.3",
"ionic-angular": "^3.6.0",
"typeorm": "0.1.11",
"reflect-metadata": "^0.1.10",
"ngx-order-pipe": "^1.1.0",
"sqlite3": "3.1.13",
"rxjs": "5.4.0"
},
"devDependencies": {
"tslint": "^5.8.0",
"tslint-eslint-rules": "^4.1.1",
"ts-node": "4.1.0",
"typescript": "^2.6.1"
} I would like to see what get generated with my current entity models definitions, was trying to do 'insitu'. I guess I will try to generate a project from scratch and copy paste entities. But would be nice if I can get it up running in my existent project. thanks in advance for your time, |
It seems my problem is known here, related to my settings: Sorry to introduce this noise. Thanks!! |
@davidmpaz how did you resolve the issue? These are my current config files
|
@91debug currently I haven't. |
@davidmpaz i resolved! thank you |
@91debug, could you share ? :) |
I used this command |
it's surprising that typeorm cli doesn't work with typescript by default without asking user to explicitly pass through ts-node. Is that something which could be built in given how typeorm itself is written in typescript? |
I found a way to make migratons work with my ionic 3 application.
and the connection:
tsconfig.json
|
@SaeedSyedAli96 how does it work? |
@tonyxiao I just used migration cli to generate migrations as it needs timestamp. Else Entitites and and other stuff I did manually. I was having issues in running migration from cli but then I got to know that there is an option of migrationsRun as well. |
Also, in Win 10 works: |
for es project in win 10
|
I had a similar issue when running my JavaScript application code (which has been transpiled from TypeScript):
I solved it by pointing the This configuration now works for me: ormconfig.js const ConnectionOptions = {
cli: {
entitiesDir: 'src/main/entity',
migrationsDir: 'src/migration',
subscribersDir: 'src/subscriber',
},
database: 'database/development.db3',
entities: ['dist/entity/*.js'],
logging: false,
migrations: ['src/migration/**/*.ts'],
subscribers: ['src/subscriber/**/*.ts'],
synchronize: true,
type: 'sqlite',
};
if (process.env.NODE_ENV === 'production') {
ConnectionOptions.database = 'database/production.db3';
}
if (process.env.NODE_ENV === 'test') {
ConnectionOptions.database = 'database/test.db3';
}
module.exports = ConnectionOptions; |
after long I installed ts-node and typescript globally and use {
/* ... */
"scripts": {
/* ... */
"typeorm-migration-generate": "ts-node ./node_modules/typeorm/cli.js migration:generate -n MigrationName",
"typeorm-migration-run": "ts-node ./node_modules/typeorm/cli.js migration:run",
"typeorm-migration-revert": "ts-node ./node_modules/typeorm/cli.js migration:revert"
}
} now i can just run |
"entities": [
"src/entity/**/*.ts"
],
"migrations": [
"src/migration/**/*.ts"
],
"subscribers": [
"src/subscriber/**/*.ts"
], 我遇到了同样 的 问题在将 ormconfig.json中的 ts 改为 js之后解决了问题 |
this changes killed my build. |
Using ENV variables, the fix for me was
Hope this helps someone |
If you are using
NOTE: Please refer to the "dist" folder and not the root folder... |
@willianfalbo I ran into a similar issue with deploying the compiled js code to server. I was very confused how any ts file was referenced to the compiled code. Didn't even think about checking ormconfig.json...Thanks so much!!! |
|
My solution was to install sudo npm install -g typescript ts-node
ts-node ./node_modules/typeorm/cli.js migration:generate -n FirstMigration |
I wrote everything in typescript.
The application and everything work fine, but as soon as I call
typeorm migrations:run
I get this error
src/entity/User.ts:1
(function (exports, require, module, __filename, __dirname) { import {Entity, Column, PrimaryGeneratedColumn} from "typeorm";
^^^^^^
SyntaxError: Unexpected token import
at Object.exports.runInThisContext (vm.js:78:16)
at Module._compile (module.js:543:28)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at Function.PlatformTools.load (/usr/local/lib/node_modules/typeorm/platform/PlatformTools.js:26:20)
at /usr/local/lib/node_modules/typeorm/util/DirectoryExportedClassesLoader.js:29:69
(node:38469) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 5): SyntaxError: Unexpected token import
(node:38469) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Not sure if it matters but this is my tsconfig.json:
{
"compilerOptions": {
"declaration": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"isolatedModules": false,
"module": "commonjs",
"moduleResolution": "node",
"outDir": "dist",
"sourceMap": true,
"sourceRoot": "src",
"noEmitHelpers": false,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": ["es6", "dom"]
},
"exclude": [
"node_modules"
]
}
What ever I change in tsconfig.json seems to not effect the error at all.
The text was updated successfully, but these errors were encountered: