Next.js Discord

Discord Forum

Missing exports when deploying to Vercel

Answered
TensorPho posted this in #help-forum
Open in Discord
I seem to be having issues with react exports. First time I've tried deploying an app before so not sure if i've missed a form of config somewhere for this however i think it might be related to my package.json file. Here is the error-
 ⨯ file:///var/task/node_modules/react-chartjs-2/dist/index.js:1
import React, { forwardRef, useRef, useEffect } from 'react';
                ^^^^^^^^^^
SyntaxError: Named export 'forwardRef' not found. The requested module 'react' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'react';
const { forwardRef, useRef, useEffect } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:190:5) {
  page: '/'
}
file:///var/task/node_modules/react-chartjs-2/dist/index.js:1
import React, { forwardRef, useRef, useEffect } from 'react';
                ^^^^^^^^^^
SyntaxError: Named export 'forwardRef' not found. The requested module 'react' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'react';
const { forwardRef, useRef, useEffect } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:190:5) {
  page: '/'
}
Error: Runtime exited with error: exit status 1
Runtime.ExitError
Answered by TensorPho
changed the chart library to fix.
View full answer

5 Replies

and this is my package.json
{
  "name": "spotify",
  "version": "0.2.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@headlessui/react": "^1.7.17",
    "@heroicons/react": "^2.0.18",
    "autoprefixer": "^10.4.16",
    "chart.js": "^4.4.0",
    "lodash": "^4.17.21",
    "next": "14.0.0",
    "next-auth": "^4.24.4",
    "postcss": "^8.4.31",
    "react": "18.2.0",
    "react-chartjs-2": "^5.2.0",
    "react-dom": "18.2.0",
    "recoil": "^0.7.7",
    "spotify-web-api-node": "^5.0.2",
    "superagent": "^8.1.2",
    "tailwind-scrollbar-hide": "^1.1.7"
  },
  "devDependencies": {
    "eslint": "8.52.0",
    "eslint-config-next": "14.0.0",
    "tailwindcss": "^3.3.5"
  }
}
I did a bit of research to people saying that it was to do with the fact it wasn't a typescript component but all my code is written in .js. It doesn't seem to be an issue with my code itself but rather the packages that use react
or there is a configuration option somewhere which is making it think it should be using typescript
Edit. I removed chart-js2 and the charts I have and it will deploy and work but idk why it wont otherwise and I'd like those charts.
changed the chart library to fix.
Answer