NewbG
NewbG

Reputation: 81

SyntaxError: Unexpected token 'export' - Angular SSR build

I'm getting the following output when trying to build my Angular 8 Universal project. I use Webpack and SSR:

myproject/node_modules/universal-analytics/node_modules/uuid/dist/esm-browser/index.js:1
export { default as v1 } from './v1.js';
^^^^^^

**SyntaxError: Unexpected token 'export'**
    at wrapSafe (internal/modules/cjs/loader.js:1055:16)
    at Module._compile (internal/modules/cjs/loader.js:1103:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1159:10)
    at Module.load (internal/modules/cjs/loader.js:988:32)
    at Function.Module._load (internal/modules/cjs/loader.js:896:14)
    at Module.require (internal/modules/cjs/loader.js:1028:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/myProject/node_modules/universal-analytics/lib/index.js:3:12)
    at Module._compile (internal/modules/cjs/loader.js:1139:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1159:10)

It was working perfectly until today when I had to run npm install.

My tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "baseUrl": "src",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es2015",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2016",
      "dom"
    ],
    "module": "esnext",
    "resolveJsonModule": true
  }
}

Has anyone else seen this or got any idea how I can try to resolve?

Upvotes: 2

Views: 2791

Answers (1)

NewbG
NewbG

Reputation: 81

This appears to have been caused by NPM caching some of my node_modules so that when I ran a fresh npm i, some modules were not correctly updating. I switched to yarn and that solved the issue :)

Upvotes: 1

Related Questions