Gatsby: Module.createRequireFromPath() is deprecated.

Created on 19 Nov 2019  路  6Comments  路  Source: gatsbyjs/gatsby

Description

Module.createRequireFromPath() is deprecated as of Node v13.1.0. An error is thrown when it is used.

Steps to reproduce

  1. Upgrade to node v13.1.0 (can also use nvm or n to just use it)
  2. Grab a project and start/build it.

Expected result

No deprecation warnings from core when using latest stable version of Node.js.

Actual result

This is logged to the console during the load plugins lifecycle:

 ERROR 

(node:9331) [DEP0130] DeprecationWarning: Module.createRequireFromPath() is deprecated. Use Module.createRequire() instead.

Line 6 of gatsby/src/utils/create-require-from-path.js is causing it.

Proposed solution

A simple solution could be to just remove line 4 (polyfill comment) and line 6 and continue using the function as is.

If that's the route you'd like to take, let me know and I'd be happy to open a quick PR for it.

Thanks!

good first issue

Most helpful comment

I needed to run: npm install gatsby@latest to fix this issue. I post this here for others who might stumble upon this.

All 6 comments

@hu0p Thanks for the report! I don't think we can remove the polyfill comment because we support back to Node 8.

It seems like we just need to add the new api and order them correctly.

Something like.

module.exports = Module.createRequire || Module.createRequireFromPath ||
  function(filename) {...}

Would you be interested in contributing this fix and testing it?

Created this PR and can confirm it removes the deprecation warning 馃憤

https://github.com/gatsbyjs/gatsby/pull/19677

Published in gatsby 2.18.2

I just encountered this same issue when spinning up my first Gatsby site. I ran npx gatsby new gatsby-site from the Quick Start video.

Did a quick Google for the issue, landed here, went to Releases page to see if 2.18.2 had landed, and it has. So, I'm thinking it must be lag in the publishing from my end, as I see 2.18.2 was published "6 hours ago" on GH Releases _and_ npmjs.org

Never mind, I forgot I had system version installed and had to update. 馃う鈥嶁檪

I needed to run: npm install gatsby@latest to fix this issue. I post this here for others who might stumble upon this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

signalwerk picture signalwerk  路  3Comments

mikestopcontinues picture mikestopcontinues  路  3Comments

theduke picture theduke  路  3Comments

brandonmp picture brandonmp  路  3Comments

Oppenheimer1 picture Oppenheimer1  路  3Comments