Martin J
Martin J

Reputation: 2159

api.targets is not a function in plugin-proposal-object-rest-spread

I have this error when I try to compile my app. The error comes from babel-plugin-proposal-object-rest-spread here https://github.com/babel/babel/blob/6e551ae8827d064680c1344074db9fb3093967e9/packages/babel-plugin-proposal-object-rest-spread/src/index.js#L22 :

Trace: error TypeError: api.targets is not a function | at /home/username/Documents/front-newlook/node_modules/next/node_modules/@babel/preset-env/node_modules/@babel/plugin-proposal-object-rest-spread/lib/index.js:38:25 | at /home/username/Documents/front-newlook/node_modules/next/node_modules/@babel/preset-env/node_modules/@babel/helper-plugin-utils/lib/index.js:19:12 | at /home/username/Documents/front-newlook/node_modules/next/node_modules/@babel/core/lib/config/full.js:166:14 | at cachedFunction (/home/username/Documents/front-newlook/node_modules/next/node_modules/@babel/core/lib/config/caching.js:32:19) | at loadPluginDescriptor (/home/username/Documents/front-newlook/node_modules/next/node_modules/@babel/core/lib/config/full.js:201:28) | at /home/username/Documents/front-newlook/node_modules/next/node_modules/@babel/core/lib/config/full.js:71:20

My babel.config.json is like this:

{
  "plugins": [
    "emotion",
    "macros",
    "@babel/plugin-proposal-class-properties"
  ],
  "presets": ["next/babel"],
  "env": {
    "test": {
      "plugins": ["require-context-hook"]
    }
  }
}

Does anyone has an idea? Thank you

Upvotes: 3

Views: 3791

Answers (2)

Martin J
Martin J

Reputation: 2159

The problem was solved when I removed the node_modules folder and then ran yarn install

Upvotes: 9

Saket Shrivastava
Saket Shrivastava

Reputation: 11

Run "npm install" once, It will fix the issue.

Upvotes: 1

Related Questions