question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unexpected token import

See original GitHub issue

Environment

Knex version: 0.95.11 Database + version: sqlite3 version 5.0.2 OS: Windows 10

Bug

  1. Hi, I am trying to perform the following operation to migrate a database to heroku: heroku run knex migrate:latest -a my-custom-app-name

  2. Error message Unexpected token import /app/node_modules/knex/lib/migrations/util/import-file.js:11 ? import(require('url').pathToFileURL(filepath)) ^^^^^^

    SyntaxError: Unexpected token import at createScript (vm.js:80:10) at Object.runInThisContext (vm.js:139:10) at Module._compile (module.js:617:28) at Object.Module._extensions..js (module.js:664:10) at Module.load (module.js:566:32) at tryModuleLoad (module.js:506:12) at Function.Module._load (module.js:498:3) at Module.require (module.js:597:17) at require (internal/module.js:11:18) at openKnexfile (/app/node_modules/knex/bin/cli.js:32:22)

Has anyone encountered a similar error? p.s. I tried to use commonjs instead of es6, it didn’t help, because the error is in the file ./node_modules/knex/lib/migrations/util/import-file.js

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
DunaevViktorcommented, Oct 25, 2021

Solved😃

0reactions
DunaevViktorcommented, Oct 25, 2021

Can you try this? (not sure if --version will be applied to node)

heroku run node --version

I seem to have found information on this here.

My old settings were as follows:

"engines": {
      "node": "8.12.0",
      "npm": "6.4.1"
},

After that I changed the settings to (same as the updated local version):

"node": "14.18.1",
"npm": "6.14.15"

But the problem remained.

upd: Oooh, I forgot to deploy changes to heroku app. After deployment, everything worked! Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node.js - SyntaxError: Unexpected token import - Stack Overflow
Use transpiler like Babel to use import in Nodejs as it is not natively supported in nodejs.There is best alternative of import is...
Read more >
SyntaxError: Unexpected token import in Node.js | bobbyhadz
The "SyntaxError: Unexpected token import" occurs when we use the ES6 import syntax in a version of Node that doesn't support it. To...
Read more >
Unexpected token import Node.js - Reactgo
In this tutorial, we are going to learn about how to resolve the unexpected token import error in Node.js.
Read more >
Nodejs Uncaught SyntaxError: Unexpected token import
An unexpected token import occurs when an error message appears in the console while running a web application.
Read more >
Error Unexpected token import in nodejs | Edureka Community
SyntaxError: Unexpected token import at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:387:25) at Object.Module.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found