Reactgo: Throw "Error: Unexpected token import" after running "npm run sequelize db:migrate"

Created on 12 Jan 2017  路  14Comments  路  Source: reactGo/reactGo

Followed the instruction from this https://github.com/reactGo/reactGo/blob/master/docs/databases.md
to setup the Postgres database.
But it threw an error message,
Sequelize [Node: 7.4.0, CLI: 2.5.1, ORM: 3.29.0]
Error reading "server/db/sequelize/sequelize_config.js". Error: Unexpected token import"
after running npm run sequelize db:migrate command.

bug help wanted

Most helpful comment

The error was introduced when I made everything import, including sequelize/sequelize_config.js. I tried running the command through babel-node but does not work.

For now, the workaround can be with changing .sequelizerc to point to

config: './server/db/postgres/sequelize_config.js',

to directly access the files!

All 14 comments

Thanks for raising issue. It might be a regression since we webpack server side node

The error was introduced when I made everything import, including sequelize/sequelize_config.js. I tried running the command through babel-node but does not work.

For now, the workaround can be with changing .sequelizerc to point to

config: './server/db/postgres/sequelize_config.js',

to directly access the files!

Cool~ It works!! I did try babel-node without luck as well.
But I can start using it for a project now, thanks!

I was getting a "reserved word" error when trying to run postgres db migrations and this fixed that as well. Thanks.

The error was introduced when I made everything import, including sequelize/sequelize_config.js. I tried running the command through babel-node but does not work.

Rename webpack.config.js to webpack.config.babel.js and add /.babelrc with the following code:

{
  "presets": [
    "es2015"
  ]
}

You'll be able to use import statements in webpack's config as well.

@jsprzybylski that did not work for me. Is there anything else that you did?

@gemfarmer does @jsprzybylski solution did not work?

Is it ok that i'm getting this issue?
Tried 3 different machines, still failed to migrate.

@choonkending I think we need to fix this. It does not work out-of-the-box as is. And even if there is a CJS compatible config for postgresql, there does not seem to be one for mongo. We should probably do one of

  1. use babel-node in our sequelize script (I haven't got this working)
  2. change related code to be CJS compatible
  3. something else?

Something else: Maybe we need to think about stopping running babel on the _whole_ server side code. Maybe we just need to run it on the react related stuff (starting point would be middleware.js). That would allows us to use mongo/postgresql and any other module without worrying about babel or cases like this.

@slavab89 that's an interesting thought, and somewhat related to #924. I have been experimenting with different approaches to switching out nodemon for either chokidar or webpack. Having a server that does not require transpialtion would make that a lot easier.

The very big downside to that is that it is not only React, but also other features which requires transpiling, such as async / await, object destructuring, class variable declarations, lexically bound class members etc. (depending on what version of node you are using)

yes that is correct, you would be "limited" to what node allows you to do, so you wont be able to use import and other features that you've mentioned (in node 6 for example). You are still able to do all the things that you want to do therefore i dont really see such a big downside here, you would just need to be aware of what you're working on.
Moreover, in case you want to take out some of the code of the server side to a different dedicated API project, it would be pretty easy because it would be regular and standard node code.

If you think that this is to much of a hassle then we'll have to find ways to deal with all of those different cases 馃槃

@slavab89

You are still able to do all the things that you want to do therefore i dont really see such a big downside here

I kind of disagree, because having to worry about two different syntax sets on the server and client adds a lot of mental overhead, as well as limits what can be shared between the two platforms. Depending on node version, there can be alot of unsupported syntax.

I do think there is a solution which would make for a good developer experience both on the client and on the server though, making use of webpack + babel on both ends. Within the scope of this issue, I think the best solution would be to make sequelize play well with ES6.

This really needs to be resolved. Maybe by doing what this SO post suggests.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

azamatsmith picture azamatsmith  路  6Comments

choonkending picture choonkending  路  4Comments

evansteelepdx picture evansteelepdx  路  3Comments

choonkending picture choonkending  路  9Comments

zacharybrady picture zacharybrady  路  4Comments