Nodejs import SyntaxError: Unexpected identifier

Hi there! :smiley:

I wanted to host my nodejs API but when I ran it for the first time I had this error:

import debug from 'debug';

SyntaxError: Unexpected identifier

It doesn’t appear when I run it locally (with node v16.0.0).
Usually, when we have this issue we have to upgrade node. So what I tried to do is to add:
"engines": { "node": "15.x" },
In my package.json.
But it didn’t solve my issue. :pensive: (I’ve also tried with 12.x and 14.x).

Do you have any idea? :grin:

cheers! :wink:

Hi, the highest node version glitch supports is 14.x, so best to stick with that.
Is the file that this code is in a .mjs file, or do you have "type": "module" in your package.json? If neither of these are the case, it won’t work.
If you’ve got everything set up correctly, it should all work ¯\_(ツ)_/¯

1 Like

Thanks for your reply!

Indeed I’ve got “type”: “module” so it’s fine. And yeah, as I said, it works locally so I don’t believe it has something to do with that :grinning_face_with_smiling_eyes:.

Thanks for trying to help

Seriously best not to “just guess” but rather to determine what is wrong. Even if a version 15 of Node seemed to work it wouldn’t have been the cause.

Are you following an example for using this library? I switch back and forth on the ES6 syntax but it appears that Debug is a class and should be import Debug from ‘debug’. Then you initialize a debug instance from it.

Hi @bricefriha - I’d love to see better why this is happening on Glitch. Could you email with the name of the project so I can take a look and see if this is a bug on our end? In your email, say that Jenn sent you!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.