Unexpected token export in NextJS 5 application

421 views Asked by At

I am trying to use date-holidays npm package in my NextJS 5 application. This package has a dependency on another package called astronomia. I am using Babel 6. When I build the application it throws the following error.

/app/node_modules/astronomia/data/vsop87Bearth.js:2611
export default m;
^^^^^^

SyntaxError: Unexpected token export
    at Module._compile (internal/modules/cjs/loader.js:723:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/irfan/Projects/sourcetree/swapwise/swapwise-web-app/node_modules/babel-register/lib/node.js:152:7)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/Users/irfan/Projects/sourcetree/swapwise/swapwise-web-app/node_modules/date-holidays-parser/lib/vsop87Bearth.cjs:5:21)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/irfan/Projects/sourcetree/swapwise/swapwise-web-app/node_modules/babel-register/lib/node.js:152:7)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)

The contents of my .babelrc are as follow:

{
  "presets": ["next/babel"],
  "plugins": [
    ["module-resolver", { "root": ["./"] }]
  ]
}

I am not sure how to get babel to transpile vsop87Bearth.js and other js files under data folder. I have tried using preset-env in various places but nothing worked. I am not sure that I even need to use preset-env since I am using Next 5.

I am using es2015 and stage-2 presets in a script in package.json

"nodemon --exec cross-env NODE_ENV=development BUILD_ENV=dev NODE_TLS_REJECT_UNAUTHORIZED=0 babel-node server --presets env es2015 stage-2"

Any help would be appreciated.

0

There are 0 answers