PuskarShestha
PuskarShestha

Reputation: 855

Creating a migration in knex.js is throwing an error

I am trying to create a migration and it throws the following error

yarn run v1.6.0
(node:14212) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usabil
ity issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods in
stead.
$ babel-node node_modules/.bin/knex migrate:make create_linky_table
C:\Users\Sagar\Desktop\linky\api\node_modules\.bin\knex:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
          ^^^^^^^

SyntaxError: missing ) after argument list
    at new Script (vm.js:79:7)
    at createScript (vm.js:251:10)
    at Object.runInThisContext (vm.js:303:10)
    at Module._compile (internal/modules/cjs/loader.js:656:28)
    at Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Object.newLoader [as .js] (C:\Users\Sagar\Desktop\linky\lms-linky\api\node_modules\pi
rates\lib\index.js:88:7)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I have the following set up in my script in package.json

"knex": "babel-node --require ./node_modules/dotenv/config node_modules/.bin/knex --knexfile='src/knexfile.js'",

I am using the following code to create the migration

yarn knex make:migration create_linky_table

I am currently using windows and i came upon this answer . Could it be a windows issue?

Upvotes: 3

Views: 2451

Answers (2)

Shaggie
Shaggie

Reputation: 1829

What @Mikael Lepistö said is correct.

I faced similar issue while doing migration scripts on windows.

My previous command was:

babel-node node_modules/.bin/knex --knexfile src/database/knexfile.js migrate:latest

I changed it to:

babel-node node_modules/knex/bin/cli.js --knexfile src/database/knexfile.js migrate:latest

And the error has gone. May be changing the reference from .bin/knex to /knex/bin/cli.js will make the magic for youso give it a try

Upvotes: 6

Mikael Lepistö
Mikael Lepistö

Reputation: 19728

Sounds like C:\Users\Sagar\Desktop\linky\api\node_modules\.bin\knex script in windows is not JavaScript executable, but actually shell script wrapper in Windows. So when you try to use babel-node or node to execute it, node interpreter fails because you are trying to run bash/sh shell script with it.

Check out what is stored inside the C:\Users\Sagar\Desktop\linky\api\node_modules\.bin\knex script and if there is a way to override, which node interpreter is used, you can override it with babel-node. If there is no way to override it, you can just check out if it calls for example node_modules/knex/bin/cli.js and call directly that with babel-node.

I would check those out myself, but I don't have Windows node tools setup on this desktop.

Upvotes: 1

Related Questions