0

I am getting the below error after initializing pusher on nextjs application:

export { Client, RegistrationState, TokenProvider };
^^^^^^
SyntaxError: Unexpected token 'export'

I have also tried modifying the next.config.js file to the following:

const withTM = require("next-transpile-modules")(["@pusher/push-notifications-web"])
module.exports = withTM({
  env: {
    apiBaseUrl: "",
    apiBaseUrlChat: ""
  },
});

When I am trying to execute npm run dev, it is giving me the following error:

TypeError: modules.map is not a function
hs27
  • 65
  • 8
  • This looks to have been answered at https://stackoverflow.com/questions/65936222/next-js-syntaxerror-unexpected-token-export. In short, you may need to: Try to modify the webpack config in next.config.js file to let the babel loader transpile the es6 dependency. You may want to use this package next-transpile-modules – doydoy Jul 01 '21 at 14:56
  • Thanks for your response @doydoy, can you share code sample for that? – hs27 Jul 02 '21 at 09:36
  • The problem for me was that the lib I used was missing an entry file. What fixed it for me was to add an empty `index.js` to the package, doing so `next-transpile-modules` worked and I was able to use the lib. Sounds stupid, but that did the job in my case. – Johnny Kontrolletti Jul 05 '21 at 08:04
  • Thanks @Tim. But I don't push node_modules file to the server. I can't do that. – hs27 Jul 05 '21 at 10:20
  • @hs27 But you could try to manually add an index.js to your client's `node_modules` to check whether or not this is the issue. – Johnny Kontrolletti Jul 05 '21 at 10:21
  • @Tim I tried that, but I get the following error: `ready - started server on 0.0.0.0:3000, url: http://localhost:3000 info - Using webpack 4. Reason: custom webpack configuration in next.config.js https://nextjs.org/docs/messages/webpack5 info - automatically enabled Fast Refresh for 1 custom loader (node:18500) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'startsWith' of undefined ` – hs27 Jul 05 '21 at 14:01

0 Answers0