3

When running:

npx knex migrate:latest

I get this error:

error

What is this .npm directory for in /home/raj/.npm/_npx/8138/lib/node_modules/knex/lib/util/import-file.js ? Is it some cache that can be deleted?

I updated Knex to 0.21.5 so it could work with "type":"module" set in my package.json for ESM syntax, but I still get this complaint. My node.js project uses import statements, not require() calls, so confused about what is causing this. Additionally, Knex's command line tool is also updated to the latest:

versions

Might it still have something to do with Knex's command line tool? Some nvm or npx cache? Or something else?

Raj
  • 1,555
  • 18
  • 32

2 Answers2

2

It's because for ESM to work, the command needs to be run with an --esm argument:

npx knex --esm migrate:latest
Raj
  • 1,555
  • 18
  • 32
1

My project is defined with "type": "module" in package.json Therefore I renamed knexfile.js to knexfile.cjs

Here is the full command

npx knex --esm --knexfile knexfile.cjs migrate:make my_migration

This will produce a migration file my_migration.cjs

xuesheng
  • 3,396
  • 2
  • 29
  • 38