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 - first build

See original GitHub issue

Node version: 6.9.5

npm version: 3.10.10

Operating system: Windows 10

Command line used: Git Bash

Steps to reproduce:

  • Clone the project
  • Run npm install
  • Run npm run setup
  • Error appears
(function (exports, require, module, __filename, __dirname) { import { chalkSuccess } from './chalkConfig';
                                                              ^^^^^^

SyntaxError: Unexpected token import
    at Object.exports.runInThisContext (vm.js:76:16)
    at Module._compile (module.js:542:28)
    at loader (C:\Users\{project folder}\node_modules\babel-register\lib\node.js:144:5)
    at Object.require.extensions.(anonymous function) [as .js] (C:\Users\{project folder}\node_modules\babel-register\lib\node.js:154:7)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Function.Module.runMain (module.js:604:10)
    at C:\Users\{project folder}\node_modules\babel-cli\lib\_babel-node.js:159:24
    at Object.<anonymous> (C:\Users\{project folder}\node_modules\babel-cli\lib\_babel-node.js:160:7)```

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
steveacalabrocommented, Mar 30, 2017

I confirmed that the file was there.

I found the reason why in case anyone else comes across this issue. It is specifically a problem with windows machines I believe. I tried the setup on my Ubuntu box and it works fine.

When working with windows you need to have the following installed npm install --save-dev cross-env.

The reason behind this is that the NODE_ENV var on my machine was set to production and I was unable to set it to development without that module. Once installed and the NODE_ENV=development command was run everything worked out ok.

0reactions
ICeZer0commented, Apr 5, 2017

oh wow, ok thanks! I think once I uninstalled the demo project it took my babel away and I was lost 😢.

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 >
Unexpected token import Error in TypeScript | bobbyhadz
To solve the Uncaught SyntaxError: Unexpected token import in TypeScript, set the `module` option to `commonjs` in your `tsconfig.json` file and make sure ......
Read more >
Unexpected token Identifier error - Import OpenLayers
This form is inteneded for development environment (like node.js and npm ), where you can run it uncompiled and then has to compiled...
Read more >
How I Fixed The Unexpected Token Error In Jest
Jest encountered an unexpected token. Depending upon your setup, you might see the error on the first line of the code file or...
Read more >
Cant build my vuejs app on production but can locally ... - Reddit
import { performance } from 'node:perf_hooks'. ^. SyntaxError: Unexpected token {. at Module._compile (internal/modules/cjs/loader.js:721:23).
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