Skip to content
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

Error when generating migration #3

Open
mlm625 opened this issue Sep 28, 2020 · 5 comments
Open

Error when generating migration #3

mlm625 opened this issue Sep 28, 2020 · 5 comments

Comments

@mlm625
Copy link

mlm625 commented Sep 28, 2020

I'm playing with typeorm for my expo project, but I can't seem to generate an initial migration. I get the following error:

$ typeorm migration:generate -n InitialMigration
Error during migration generation:
C:\Users\...\node_modules\expo-sqlite\build\index.js:1
export * from './SQLite';
^^^^^^

SyntaxError: Unexpected token 'export'
    at wrapSafe (internal/modules/cjs/loader.js:1053:16)
    at Module._compile (internal/modules/cjs/loader.js:1101:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)
    at Module.require (internal/modules/cjs/loader.js:1025:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (C:\Users\Ming\git\TheGreenerThumb\ormconfig.js:5:11)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)

My ormconfig.js looks like:

module.exports = {
  type: 'expo',
  driver: require('expo-sqlite'),
  database: 'plants',
  location: 'default',
  synchronize: false,
  logging: ['error', 'schema'],
  logger: 'simple-console',
  entities: [
    'src/entities/*.ts',
  ],
};
@cuibonobo
Copy link
Collaborator

This seems like a transpilation issue. Could you post what your tsconfig.json looks like?

@mknaw
Copy link

mknaw commented Mar 26, 2021

Experiencing the same as OP. My tsconfig:

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "jsx": "react-native",
    "lib": ["dom", "esnext"],
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "noEmit": true,
    "skipLibCheck": true,
    "resolveJsonModule": true,
    "strict": true,
    "strictPropertyInitialization": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true
  }
}

My impression (take with a grain of salt, as I know nothing about node) is that something is wrong in reading the ormconfig.js generally; using createConnection() with no args does not seem to successfully read the config file as suggested by the TypeORM docs. I have a hunch that behavior is related to this migration behavior.

@nmartinezb3
Copy link

The same is happening to me. The issue is the same as here: TypeStrong/ts-node#935
I think that the error is caused because ts-node can only load commonjs modules. I've tried to set "target": "commonjs" in expo-sqlite, recompiled and the error is gone, but now the same appears while importing @unimodules dependency, so it needs to be set in every module 🤔

Here is my tsconfig.json:

{
  "extends": "expo/tsconfig.base",
  "compilerOptions": {
    "module": "commonjs",
    "allowJs": true,
    "esModuleInterop": true,
    "moduleResolution": "node",
    "strict": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "strictPropertyInitialization": false,
    "baseUrl": "./"
  }
}

Any ideas? I really need to make the migrations work on expo.

@DLawla
Copy link

DLawla commented Feb 22, 2022

@nmartinezb3 Just curious if you had any luck with this last year?

@L-U-C-K-Y
Copy link

I am also facing this issue, any advice?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants