db-migrate / node-db-migrate

Database migration framework for node
Other
2.32k stars 360 forks source link

Help with config to enable ES6 syntax #650

Closed U-4-E-A closed 4 years ago

U-4-E-A commented 5 years ago

I'm submitting a...

Really hoping someone can help me with this as it's driving me crazy.

Node v12.4.0

package.json: -

{
"name": "@mypackage/db-migrate",
"private": true,
"version": "1.0.0",
"main": "index.js",
"license": "ISC",
"workspaces": {
"packages": [
"common/models"
]
},
"dependencies": {
"@babel/core": "^7.6.0",
"@babel/preset-env": "^7.6.0",
"@babel/register": "^7.6.0",
"@mypackage/models": "1.0.0",
"db-migrate-mysql": "^1.1.10",
"db-migrate-plugin-babel": "^2.0.1",
"npm-upgrade": "^2.0.2"
}
}

.babelrc: -

{
"presets": [
"@babel/preset-env"
]
}

Directory structure: -

common->models - this contains the source lib for @mypackage/models

migrations - contains all the migration files

Yarn installs all the dependencies without issue.

So when I run a migration command ("db-migrate down -c 1", for example), I get the following: -

export { CONSTANT_ONE, CONSTANT_TWO, CONSTANT_THREE };

^^^^^^

SyntaxError: Unexpected token export

This is happening when I am trying to export/import from one of the @mypackage/models files.

var CONSTANT_ONE = "foo_one";
var CONSTANT_TWO = "foo_two";
var CONSTANT_THREE = "foo_three";

export { CONSTANT_ONE, CONSTANT_TWO, CONSTANT_THREE };

I have tried placing the @mypackage/models file in a directory inside of the directory containing the migrations themselves and this appears to import and export without issue. Is this a root directory issue? I am complete baffled and utterly frustrated. Any help VERY welcome.

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/81271965-help-with-config-to-enable-es6-syntax?utm_campaign=plugin&utm_content=tracker%2F73887&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F73887&utm_medium=issues&utm_source=github).
wzrdtales commented 5 years ago

That would need to hook in, so a plugin for babel would be needed. There is a plugin for coffee script already, so have a look here https://github.com/db-migrate/plugin-coffee/blob/master/index.js and feel free to publish a plugin for babel.

wzrdtales commented 5 years ago

https://www.npmjs.com/package/db-migrate-plugin-babel

In fact there is a plugin already.

U-4-E-A commented 5 years ago

Solved by changing .babelrc to babel.config.js.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.