Skip to main content
Active reading [<https://en.wikipedia.org/wiki/ECMAScript#6th_Edition_%E2%80%93_ECMAScript_2015> <https://en.wikipedia.org/wiki/Node.js>]. Expanded.
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

How can I use an es6ES6 import in nodeNode.js?

I'm trying to get the hang of ES6ES6 imports in nodeNode.js and am trying to use the syntax provided in this example:

Cheatsheet Link

I'm looking through the support table, but I was not able to find what version supports the new import statements (I tried looking for the text import/require). I'm currently running nodeNode.js 8.1.2 and also believe that since the cheatsheet is referring to .js files it should work with .js files.

As I run the code (taken from the cheatsheet's 1stfirst example):

import { square, diag } from 'lib'; 

I get the error:

SyntaxError: Unexpected token import. 

SyntaxError: Unexpected token import.

Reference to liblibrary I'm trying to import:

//------ lib.js ------ export const sqrt = Math.sqrt; export function square(x) { return x * x; } export function diag(x, y) { return sqrt(square(x) + square(y)); } 

What am I missing and how can I get node to recognize my import statement?

How can I use an es6 import in node?

I'm trying to get the hang of ES6 imports in node and am trying to use the syntax provided in this example:

Cheatsheet Link

I'm looking through the support table, but was not able to find what version supports the new import statements (I tried looking for the text import/require) I'm currently running node 8.1.2 and also believe that since the cheatsheet is referring to .js files it should work with .js files.

As I run the code (taken from cheatsheet's 1st example):

import { square, diag } from 'lib'; 

I get the error:

SyntaxError: Unexpected token import. 

Reference to lib I'm trying to import:

//------ lib.js ------ export const sqrt = Math.sqrt; export function square(x) { return x * x; } export function diag(x, y) { return sqrt(square(x) + square(y)); } 

What am I missing and how can I get node to recognize my import statement?

How can I use an ES6 import in Node.js?

I'm trying to get the hang of ES6 imports in Node.js and am trying to use the syntax provided in this example:

Cheatsheet Link

I'm looking through the support table, but I was not able to find what version supports the new import statements (I tried looking for the text import/require). I'm currently running Node.js 8.1.2 and also believe that since the cheatsheet is referring to .js files it should work with .js files.

As I run the code (taken from the cheatsheet's first example):

import { square, diag } from 'lib'; 

I get the error:

SyntaxError: Unexpected token import.

Reference to library I'm trying to import:

//------ lib.js ------ export const sqrt = Math.sqrt; export function square(x) { return x * x; } export function diag(x, y) { return sqrt(square(x) + square(y)); } 

What am I missing and how can I get node to recognize my import statement?

I'm trying to get the hang of es6ES6 imports in node and am trying to use the syntax provided in this example:

Cheatsheet Link: https://hackernoon.com/import-export-default-require-commandjs-javascript-nodejs-es6-vs-cheatsheet-different-tutorial-example-5a321738b50f

Cheatsheet Link

I'm looking through the support table: http://node.green/the support table, but was not able to find what version supports the new import statements (I tried looking for the text import/require) I'm currently running node 8.1.2 and also believe that since the cheatsheet is referring to .js files it should work with .js files.

As I run the code (taken from cheatsheet's 1st example):

import { square, diag } from 'lib'; 

I get the error:

SyntaxError: Unexpected token import. 

Reference to lib I'm trying to import:

//------ lib.js ------ export const sqrt = Math.sqrt; export function square(x) { return x * x; } export function diag(x, y) { return sqrt(square(x) + square(y)); } 

What am I missing and how can I get nodenode to recognize my importimport statement?

I'm trying to get the hang of es6 imports in node and am trying to use the syntax provided in this example:

Cheatsheet Link: https://hackernoon.com/import-export-default-require-commandjs-javascript-nodejs-es6-vs-cheatsheet-different-tutorial-example-5a321738b50f

I'm looking through the support table: http://node.green/, but was not able to find what version supports the new import statements (I tried looking for the text import/require) I'm currently running node 8.1.2 and also believe that since the cheatsheet is referring to .js files it should work with .js files.

As I run the code (taken from cheatsheet's 1st example):

import { square, diag } from 'lib'; 

I get the error:

SyntaxError: Unexpected token import. 

Reference to lib I'm trying to import:

//------ lib.js ------ export const sqrt = Math.sqrt; export function square(x) { return x * x; } export function diag(x, y) { return sqrt(square(x) + square(y)); } 

What am I missing and how can I get node to recognize my import statement?

I'm trying to get the hang of ES6 imports in node and am trying to use the syntax provided in this example:

Cheatsheet Link

I'm looking through the support table, but was not able to find what version supports the new import statements (I tried looking for the text import/require) I'm currently running node 8.1.2 and also believe that since the cheatsheet is referring to .js files it should work with .js files.

As I run the code (taken from cheatsheet's 1st example):

import { square, diag } from 'lib'; 

I get the error:

SyntaxError: Unexpected token import. 

Reference to lib I'm trying to import:

//------ lib.js ------ export const sqrt = Math.sqrt; export function square(x) { return x * x; } export function diag(x, y) { return sqrt(square(x) + square(y)); } 

What am I missing and how can I get node to recognize my import statement?

added 6 characters in body
Source Link
mikemaccana
  • 126.1k
  • 113
  • 441
  • 544

I'm trying to get the hang of es6 imports in node and am trying to use the syntax provided in this example:

Cheatsheet Link: https://hackernoon.com/import-export-default-require-commandjs-javascript-nodejs-es6-vs-cheatsheet-different-tutorial-example-5a321738b50f

I'm looking through the support table: http://node.green/, but was not able to find what version supports the new import statements (I tried looking for the text import/require) I'm currently running node 8.1.2 and also believe that since the cheatsheet is referring to .js files it should work with .js files.

As I run the code (taken from cheatsheet's 1st example):

import { square, diag } from 'lib'; 

I get the error: SyntaxError: Unexpected token import.

SyntaxError: Unexpected token import. 

Reference to lib I'm trying to import:

//------ lib.js ------ export const sqrt = Math.sqrt; export function square(x) { return x * x; } export function diag(x, y) { return sqrt(square(x) + square(y)); } 

What am I missing and how can I get node to recognize my import statement?

I'm trying to get the hang of es6 imports in node and am trying to use the syntax provided in this example:

Cheatsheet Link: https://hackernoon.com/import-export-default-require-commandjs-javascript-nodejs-es6-vs-cheatsheet-different-tutorial-example-5a321738b50f

I'm looking through the support table: http://node.green/, but was not able to find what version supports the new import statements (I tried looking for the text import/require) I'm currently running node 8.1.2 and also believe that since the cheatsheet is referring to .js files it should work with .js files.

As I run the code (taken from cheatsheet's 1st example):

import { square, diag } from 'lib'; 

I get the error: SyntaxError: Unexpected token import.

Reference to lib I'm trying to import:

//------ lib.js ------ export const sqrt = Math.sqrt; export function square(x) { return x * x; } export function diag(x, y) { return sqrt(square(x) + square(y)); } 

What am I missing and how can I get node to recognize my import statement?

I'm trying to get the hang of es6 imports in node and am trying to use the syntax provided in this example:

Cheatsheet Link: https://hackernoon.com/import-export-default-require-commandjs-javascript-nodejs-es6-vs-cheatsheet-different-tutorial-example-5a321738b50f

I'm looking through the support table: http://node.green/, but was not able to find what version supports the new import statements (I tried looking for the text import/require) I'm currently running node 8.1.2 and also believe that since the cheatsheet is referring to .js files it should work with .js files.

As I run the code (taken from cheatsheet's 1st example):

import { square, diag } from 'lib'; 

I get the error:

SyntaxError: Unexpected token import. 

Reference to lib I'm trying to import:

//------ lib.js ------ export const sqrt = Math.sqrt; export function square(x) { return x * x; } export function diag(x, y) { return sqrt(square(x) + square(y)); } 

What am I missing and how can I get node to recognize my import statement?

Post Closed as "Duplicate" by T.J. Crowder node.js
added 38 characters in body
Source Link
Jonathan002
  • 10.5k
  • 9
  • 45
  • 70
Loading
Source Link
Jonathan002
  • 10.5k
  • 9
  • 45
  • 70
Loading