3

this is my code.

import app  from './core/app'

const PORT=process.env.PORT || 3000;

app.express.listen(PORT,()=>{
    console.log(`server up and running on port ${PORT}`)
});

when i am importing my core module from core folder giving this error.

(function (exports, require, module, __filename, __dirname) { import app  from './core/app'
                                                              ^^^^^^

SyntaxError: Unexpected token import
1

1 Answer 1

3

The answer is, NodeJS environment currently does not support the import syntax. We only have one approach to load an external module is using the require() function.

Sign up to request clarification or add additional context in comments.

2 Comments

That's right, I use import all around the place, but I write Typescript, not Javascript. I had a look at the transpiled code, and all import disappear and are replaced with require.
This might be a relevant article for you: medium.com/the-node-js-collection/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.