Error: Cannot find module 'core-js/modules/es6.object.assign'
interglobalmedia opened this issue · 26 comments
Description
Describe the issue that you're seeing.
When I first ran gatsby develop, I got the warning:
WARNING: We noticed you're using the `useBuiltIns` option without declaring a core-js version. Currently, we assume version 2.x when no version is passed. Since this default version will likely change in future versions of Babel, we recommend explicitly setting the core-js version you are using via the `corejs` option.
You should also be sure that the version you pass to the `corejs` option matches the version specified in your `package.json`'s `dependencies` section. If it doesn't, you need to run one of the following commands:
npm install --save core-js@2 npm install --save core-js@3
yarn add core-js@2 yarn add core-js@3
So I installed core-js@3. Then I ran gatsby develop again, and this time I got the error which exited me out of gatsby build:
error UNHANDLED REJECTION
Error: Cannot find module 'core-js/modules/es6.object.assign'
loader.js:649 Function.Module._resolveFilename
internal/modules/cjs/loader.js:649:15
- loader.js:575 Function.Module._load
internal/modules/cjs/loader.js:575:25
- loader.js:705 Module.require
internal/modules/cjs/loader.js:705:19
- helpers.js:14 require
internal/modules/cjs/helpers.js:14:16
- render-page.js:3 webpackUniversalModuleDefinition
/Users/mariacam/Development/mariadcampbell/public/render-page.js:3:54
- render-page.js:10 Object.<anonymous>
/Users/mariacam/Development/mariadcampbell/public/render-page.js:10:3
- loader.js:799 Module._compile
internal/modules/cjs/loader.js:799:30
- loader.js:810 Object.Module._extensions..js
internal/modules/cjs/loader.js:810:10
- loader.js:666 Module.load
internal/modules/cjs/loader.js:666:32
- loader.js:606 tryModuleLoad
internal/modules/cjs/loader.js:606:12
- loader.js:598 Function.Module._load
internal/modules/cjs/loader.js:598:3
- loader.js:705 Module.require
internal/modules/cjs/loader.js:705:19
- helpers.js:14 require
internal/modules/cjs/helpers.js:14:16
- worker.js:32 Promise
[mariadcampbell]/[gatsby]/dist/utils/worker.js:32:35
- debuggability.js:313 Promise._execute
[mariadcampbell]/[bluebird]/js/release/debuggability.js:313:9
- promise.js:483 Promise._resolveFromExecutor
[mariadcampbell]/[bluebird]/js/release/promise.js:483:18
Maria-Campbells-Computer-2 ॐ ~/development/mariadcampbell:(25m|git@master!)
11321 ±
Steps to reproduce
Clear steps describing how to reproduce the issue. Please please please link to a demo project if possible, this makes your issue much easier to diagnose (seriously).
Expected result
What should happen?
gatsby develop should have resulted in the ability for me to view the project in the browser.
Actual result
What happened.
I am using the default starter. I had a similar issue when using the starter blog, but was not exited out when running gatsby develop. Also did not install core-js. Problems started occurring and I was exited out of the program when I installed core-js@3.
Environment
Run gatsby info --clipboard
in your project directory and paste the output here.
gatsby info --clipboard ⏎ ✹
System:
OS: macOS 10.14.3
CPU: (8) x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
Shell: 5.3 - /bin/zsh
Binaries:
Node: 11.12.0 - ~/.nvm/versions/node/v11.12.0/bin/node
npm: 6.7.0 - ~/.nvm/versions/node/v11.12.0/bin/npm
Languages:
Python: 2.7.15 - /usr/local/bin/python
Browsers:
Firefox: 36.0.4
npmPackages:
gatsby: ^2.2.5 => 2.2.5
gatsby-image: ^2.0.34 => 2.0.34
gatsby-plugin-manifest: ^2.0.24 => 2.0.24
gatsby-plugin-offline: ^2.0.25 => 2.0.25
gatsby-plugin-react-helmet: ^3.0.10 => 3.0.10
gatsby-plugin-sharp: ^2.0.30 => 2.0.30
gatsby-source-filesystem: ^2.0.27 => 2.0.27
gatsby-transformer-sharp: ^2.1.17 => 2.1.17
npmGlobalPackages:
gatsby-cli: 2.4.17
I really want to encounter the same problem. How did you solve it?
{
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": "usage",
"corejs": 2
}
],
"@babel/preset-react",
"minify"
],
"plugins": [
"@babel/plugin-transform-runtime"
]
}
I have similar problem, the warning about core-js started to appear since the last update (v2.2.x)
Does this belong in babel-preset-gatsby
? How would @lushijie's fix work with it?
I really want to encounter the same problem. How did you solve it?
try npm install --save core-js@2
So far I've tried both gatsby 2.1.x and 2.2.x, with and without core-js, at versions 2 and 3, deleting caches in between changes. Nothing seems to work.
What's surprising is that 2.1.x used to work until I upgraded to 2.2.x. Seems like some child dependency has been upgraded in my node_modules without a lockfile.
info bootstrap finished - 5.807 s
WARNING: We noticed you're using the `useBuiltIns` option without declaring a core-js version. Currently, we assume version 2.x when no version is passed. Since this default version will likely change in future versions of Babel, we recommend explicitly setting the core-js version you are using via the `corejs` option.
You should also be sure that the version you pass to the `corejs` option matches the version specified in your `package.json`'s `dependencies` section. If it doesn't, you need to run one of the following commands:
npm install --save core-js@2 npm install --save core-js@3
yarn add core-js@2 yarn add core-js@3
here ./.cache/develop-static-entry.js
Module build failed (from ../node_modules/gatsby/dist/utils/babel-loader.js):
TypeError: [BABEL] /home/rakesh/some-folder/.cache/develop-static-entry.js: (0 , _semver(...).coerce) is not a function (While processing: "/home/rakesh/some-folder/node_modules/@babel/preset-env/lib/index.js")
at normalizeCoreJSOption (/home/rakesh/some-folder/node_modules/@babel/preset-env/lib/normalize-options.js:173:53)
at normalizeOptions (/home/rakesh/some-folder/node_modules/@babel/preset-env/lib/normalize-options.js:192:18)
at _default (/home/rakesh/some-folder/node_modules/@babel/preset-env/lib/index.js:109:37)
at /home/rakesh/some-folder/node_modules/@babel/helper-plugin-utils/lib/index.js:19:12
at loadDescriptor (/home/rakesh/some-folder/node_modules/@babel/core/lib/config/full.js:165:14)
at cachedFunction (/home/rakesh/some-folder/node_modules/@babel/core/lib/config/caching.js:33:19)
at loadPresetDescriptor (/home/rakesh/some-folder/node_modules/@babel/core/lib/config/full.js:235:63)
at config.presets.reduce (/home/rakesh/some-folder/node_modules/@babel/core/lib/config/full.js:77:21)
at Array.reduce (<anonymous>)
at recurseDescriptors (/home/rakesh/some-folder/node_modules/@babel/core/lib/config/full.js:74:38)
at recurseDescriptors (/home/rakesh/some-folder/node_modules/@babel/core/lib/config/full.js:94:27)
at loadFullConfig (/home/rakesh/some-folder/node_modules/@babel/core/lib/config/full.js:108:6)
at process.nextTick (/home/rakesh/some-folder/node_modules/@babel/core/lib/transform.js:28:33)
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)
error There was an error compiling the html.js component for the development server.
same problem
I think we need to update babel-gatsby-preset with @lushijie comment. @rakeshpai Would you like to open a PR for this?
Oh man. Would have loved to, but I'm not too familiar with gatsby's codebase, and the last time I tried to get a fork running locally, I faced tons of issues getting the build going.
Hi, just wanted to share that I have one vulnerabilty showing at the root of my gatsby blog. It is:
npm audit ✹ ✭
=== npm audit security report ===
┌──────────────────────────────────────────────────────────────────────────────┐
│ Manual Review │
│ Some vulnerabilities require your attention to resolve │
│ │
│ Visit https://go.npm.me/audit-guide for additional guidance │
└──────────────────────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate │ Denial of Service │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package │ js-yaml │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in │ >=3.13.0 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ gatsby-plugin-sharp │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path │ gatsby-plugin-sharp > svgo > js-yaml │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info │ https://npmjs.com/advisories/788 │
└───────────────┴──────────────────────────────────────────────────────────────┘
found 1 moderate severity vulnerability in 25842 scanned packages
1 vulnerability requires manual review. See the full report for details.
However, when I went in deeper to fix this, there were much more vulnerabilities and some even critical (I am on gatsby 2.2.5. And many as also mentioned by @rakeshpai did not have lock files. When I would add one, more vulnerabilities revealed themselves. Including for babel related stuff. Just FYI. Couldn't even resolve all of them completely.
+1 for missing lockfiles. My local install of gatsby is now fubar, and I can't seem to go back to an older version. My error is the same as pasted above - about _semver(...).coerce is not defined
in @babel/preset-env
, and switching to older versions of gatsby doesn't get rid of it. The inability to go back to a previous known good state is a little frustrating. Deleting my project's lockfile isn't an option in my case. I've tried npm rm
ing gatsby and all it's plugins, rm -rf node_modules
, and npm i
to get an older known good version of gatsby back (2.1.7), but I end up in the same error state. This can only be explained by a bad/missing lockfile.
+1 for missing lockfiles. My local install of gatsby is now fubar, and I can't seem to go back to an older version. My error is the same as pasted above - about
_semver(...).coerce is not defined
in@babel/preset-env
, and switching to older versions of gatsby doesn't get rid of it. The inability to go back to a previous known good state is a little frustrating. Deleting my project's lockfile isn't an option in my case. I've triednpm rm
ing gatsby and all it's plugins,rm -rf node_modules
, andnpm i
to get an older known good version of gatsby back (2.1.7), but I end up in the same error state. This can only be explained by a bad/missing lockfile.
I notice that I have this exactly same issue.
Even removing package-lock.json
(along with node_modules
folder and .cache
; I tried everything).
The only way to "fix" it is installing core-js v2 npm install --save core-js@2
.
@anonimoconiglio I've been juggling some similar issues today, and I think the following may resolve your issue- in short upgrade gatsby, then rm your node_modules and reinstall from scratch (but same yarn.lock):
yarn upgrade gatsby
# after this you should end up with a bunch of upgrades, including
# gatsby ~ 2.2.9
# babel-preset-gatsby ~ 0.0.10
rm -rf node_modules && yarn
I believe that the reason you don't see lockfiles in individual packages is gatsbyjs/gatsby's monorepo structure- the yarn.lock
is at the top level and is for developers. More, this wouldn't affect yarn install
s for other gatsby projects specifying it- only the top-level yarn.lock
is checked on install. Below that yarn/npm rely on the manifest in each package.json to specify compatible packages. Not saying there isn't still an issue here somewhere with dependencies, just that the absence of lockfiles probably is not it.
For the specific vulnerability you found @interglobalmedia, that was just reported March 21: https://www.npmjs.com/advisories/788 - it's a requirement of several packages and should be updated but I don't believe it is directly related to this issue.
@erikdstock Thanks for all the information! FYI,I do not use yarn. I use npm. And the vulnerability shown at the top leads to a several hundred more deeper down. especially when I add a package-lock.json file when prompted to when doing npm audit fixes
.
I fixed that audit warning in #12844, btw.
You'll need to upgrade gatsby-plugin-sharp
which bumps its version of svgo
, which bumped its version of js-yaml
. Fun!
As I believe the original issue was fixed and we've now fixed this separate issue--let's close it out.
Thanks!
try npm install --save core-js@2
Thanks ! it's OK, Awesome !
For posterity, at least part of my issue was that I was hoisting gatsby's node_modules and package.json to fit in the way I had organised my monorepo. Gatsby really doesn't like this kind of hoisting. I've had to reorg parts of my repo (!) so that I don't mess with the Gatsby pieces and my issue seems to be gone.
@lushijie Not work for me.
Invalid Option: core-js is not a valid top-level option.
I'm seeing the same behaviour as @interglobalmedia. Installing core-js@2
(via npm or yarn) does not make a difference.
Where should the config from @lushijie be added? Adding it to babel-preset-gatsby/.babelrc
seemed to be incorrect.
Borrowing from a few of the solutions presented above, here's what worked for me.
My gatsby
and core-js
versions:
// in package.json dependencies
"gatsby": "~2.2.0",
"core-js": "~2",
Install babel-preset-gatsby
yarn add babel-preset-gatsby --dev
Create a file at the project root called .babelrc
and add the following:
{
"presets": ["babel-preset-gatsby"]
}
Then when I run yarn start
I no longer get the errors referenced above. Credit to those above who presented these solutions, I just wanted to pull it into one post for people -- hope it works for you.
I saw this in another issue and after some time tracked down to this specific warning that was occurring no matter what I had tried up to then.
warning gatsby > @reach/router > create-react-context > fbjs > core-js@1.2.7: core-js@<2.6.5 is no longer maintained. Please, upgrade to core-js@3 or at least to actual version of core-js@2.
so looking at it what it seemed to state was that it can't be less than core-js 2.6.5 so I force installed core-js 2.6.5 and it fixed everything. So it is almost like a circular dependency issue but stemming from reach/router.
Building with the latest versioned dependencies when building a new Gatsby project doesn't cause any such issues.
It's only if you use other libs like Recompose
that core-js
errors start to appear. Not fully sure whether it's because of inner child dependencies requiring different versions that Gatsby default babel config doesn't pick up or something else?
By the way, @jjcav84, I encountered the above-mentioned issue but couldn't solve it with core-js@3
. So I tried @2.6.5
version (which I believe is the most stable v2) and it worked, and that was with gatsby@latest
@kiley0, I bet it works fine with latest gatsby version.
In my case, I just installed version 2 of core-js and didn't need to include any Babel preset, and it worked okay. Did you try this setup?
My working setup:
"core-js": "^2.6.5",
"gatsby": "^2.4.3",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"recompose": "^0.30.0"
In my case I used static properies on class with standart Babel config which does not support static properties on classes. Maybe it will help someone.
try npm install --save core-js@2
Thank you very much i've lost 4 hours trying fix this.
I had the same issue. Perhaps i have Node v13.8.0,,, "@babel/core": "^7.8.7", "webpack": "^4.42.0",
"webpack-dev-server": "^3.10.3".
My webpack.config.js:
var modl = {
"rules": [{
"test": /.(js|jsx)$/,
exclude: /node_modules/,
"use": { "loader": "babel-loader" }
},
{ test: /.s[ac]ss$/i, use: ['style-loader', 'css-loader', 'sass-loader'] },
{ test: /.(ttf|eot|svg)(?v=[0-9].[0-9].[0-9])?$/, use: [{ loader: 'file-loader' }] },
{
test: /.woff(2)?(?v=[0-9].[0-9].[0-9])?$/,
use: [{
loader: 'url-loader',
options: { limit: 10000, mimetype: 'application/font-woff', publicPath: '../' }
}]
}
]
};
module.exports = {
"module": modl,
"devServer": {"port": 5555,index: '/'}
}
My babel.config.js:
const presets = [
[
"@babel/env",
{
"useBuiltIns": "usage",
"corejs": 2
}
],
[
"@babel/preset-react"
]
];
const plugins = [ ["@babel/plugin-proposal-class-properties", { "loose": true }] ];
module.exports = { presets, plugins };
For me works install core-js2: "core-js": "^2.6.11",
npm install --save-dev core-js@2
Hope you find useful these comment :D