Error Unexpected token import in nodejs

0 votes

I don't understand what is wrong. Node v5.6.0 NPM v3.10.6

The code:

function (exports, require, module, __filename, __dirname) {
    import express from 'express'
};

The error:

SyntaxError: Unexpected token import
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:387:25)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Function.Module.runMain (module.js:447:10)
    at startup (node.js:140:18)
    at node.js:1001:3
Apr 24, 2020 in Java-Script by kartik
• 37,510 points
8,881 views

1 answer to this question.

0 votes

Hello,

Unfortunately, Node.js doesn't support ES6's import yet.

To accomplish what you're trying to do (import the Express module), this code should suffice

var express = require("express");

Also, be sure you have Express installed by running

$ npm install express

hope this is helpful!!

Get your Node.js Certification today to become a certified expert.

Thank you!!

answered Apr 24, 2020 by Niroj
• 82,880 points

Related Questions In Java-Script

0 votes
1 answer

Error: listen EADDRINUSE while using nodejs?

Hello kartik, Two possible solutions for this: Free currently ...READ MORE

answered Apr 24, 2020 in Java-Script by Niroj
• 82,880 points
1,068 views
0 votes
1 answer

Error: Use of const in strict mode

Hello, If this is happening in nodejs, it ...READ MORE

answered Apr 24, 2020 in Java-Script by Niroj
• 82,880 points
3,295 views
+1 vote
1 answer

How to get error status code of http get NodeJS?

Hello @kartik, An error code 400 response is ...READ MORE

answered Jun 2, 2020 in Java-Script by Niroj
• 82,880 points
3,873 views
0 votes
1 answer

Parse Error: Adjacent JSX elements must be wrapped in an enclosing tag

Hello @kartik, You  just need to put your ...READ MORE

answered Jun 8, 2020 in Java-Script by Niroj
• 82,880 points
5,151 views
0 votes
1 answer

What is Laravel framework? Why one should use Laravel?

Laravel is a PHP web-framework; it utilized ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,880 points
1,391 views
0 votes
1 answer

How to download and install Lavavel framework?

Hey @kartik, First you must have xampp install ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,880 points
1,117 views
0 votes
1 answer

How can we get started with Laravel through Xampp?

Hii, First you need to start Apache and ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,880 points
781 views
0 votes
1 answer

What are the important directories used in a common Laravel application

Hey @Kartik. Directories used in a common Laravel ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,880 points
1,923 views
0 votes
1 answer

Error:Parsing JSON giving “unexpected token o” error

Hello @kartik, Your data is already an object. ...READ MORE

answered Jun 19, 2020 in Java-Script by Niroj
• 82,880 points
2,951 views
0 votes
1 answer

Error:Uncaught SyntaxError: Unexpected token

Hello @kartik, Using the jQuery command getJSON and ...READ MORE

answered Oct 9, 2020 in Java-Script by Niroj
• 82,880 points
3,475 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP