Search code examples
wordpress-gutenberg

Getting error while create a block with wordpress/create-block package


I tried to create a new block with @wordpress/create-block package and it resulted into the following error:

npm init @wordpress/block todo-list

npx: installed 205 in 10.545s
/Users/macname/.npm/_npx/89564/lib/node_modules/@wordpress/create-block/lib/scaffold.js:4
const { writeFile } = require( 'fs' ).promises;
    ^

TypeError: Cannot destructure property `writeFile` of 'undefined' or 'null'.
at Object.<anonymous> (/Users/alokjain/.npm/_npx/89564/lib/node_modules/@wordpress/create-block/lib/scaffold.js:4:38)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/alokjain/.npm/_npx/89564/lib/node_modules/@wordpress/create-block/lib/index.js:15:18)
at Module._compile (module.js:653:30)

Is there any particular node version or another package needed to run this?


Solution

  • As long as you're using node 10+, you should be able to run this.

    First, run npm cache clean --force to avoid any cache issues.

    The create-block package is very actively developed - the latest version was released just 24 hours before your post so also make sure you're using the latest version.

    You can find out the version that you're running by issuing npm init @wordpress/block -V

    If that still fails, create an issue on github.