typeorm / expo-example

Example of using the Expo driver with TypeORM
30 stars 53 forks source link

Error when generating migration #3

Open mlm625 opened 3 years ago

mlm625 commented 3 years ago

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 commented 3 years ago

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

mknaw commented 3 years ago

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 commented 3 years ago

The same is happening to me. The issue is the same as here: https://github.com/TypeStrong/ts-node/issues/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 commented 2 years ago

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

L-U-C-K-Y commented 1 year ago

I am also facing this issue, any advice?