0

I have a working node.js development environment created with Anaconda. When I have moved the project to another machine, re-created identical environment, I get error when running npm run build (or npm run dev):

[!] SyntaxError: Unexpected token {
c:\test\myproject\rollup.config.js:1
(function (exports, require, module, __filename, __dirname) { import { nodeResolve } from '@rollup/plugin-node-resolve'
                                                                     ^

SyntaxError: Unexpected token {
    at new Script (vm.js:79:7)
    at createScript (vm.js:251:10)
    at Object.runInThisContext (vm.js:303:10)
    at Module._compile (internal/modules/cjs/loader.js:656:28)
    at Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Object.require.extensions.(anonymous function) [as .js] (c:\test\myproject\node_modules\rollup\dist\shared\loadConfigFile.js:560:13)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Module.require (internal/modules/cjs/loader.js:636:17)

This is the top line of my rollup.config.js where the error occurs:

import { nodeResolve } from '@rollup/plugin-node-resolve'

Node version: v10.13.0.

I have compared npm modules installed on both machines, they are identical, with identical versions. I'm truly puzzled. I'll be grateful for any pointers where to look for differences between the two machines and how to make the project working. I've already spent half a day looking at it and I've run out of ideas.

UPDATE:

I copied the whole conda environment to the new machine to mirror the working configuration on the old machine but the error still persists. So now I have identical environments, identical source code but it works on one machine and it doesn't on another.

Andrzej
  • 1
  • 3
  • Does this answer your question? [How can I use an es6 import in node?](https://stackoverflow.com/questions/45854169/how-can-i-use-an-es6-import-in-node) – Seblor Jul 31 '20 at 19:49
  • I've seen this thread but it doesn't. I tried several NodeJS versions, I started getting different errors but no working solution. Probably I'm missing something trivial but I don't know what it is. – Andrzej Jul 31 '20 at 20:23
  • Node does not support ES6 imports natively by default. If you absolutely need it, you need to use the `experimental-modules` flag and rename your JS files with the `.mjs` extension with Node 12 or higher – Seblor Jul 31 '20 at 22:07

1 Answers1

0

It turns out rollup doesn't work properly when the project path goes through an NTFS directory junction.

Sample layout:

C:\Home                   - directory
    \Work                 - directory
       \MyProject         - directory

C:\Work                   - junction to C:\Home\Work

Results:

cd C:\Work\MyProject
npm run build
     .... results in error

cd C:\Home\Work\MyProject
npm run build 
      .... everything works OK 
Andrzej
  • 1
  • 3