create-guten-block icon indicating copy to clipboard operation
create-guten-block copied to clipboard

Build: If no SCSS files, don't attempt to build CSS files

Open Viper007Bond opened this issue 6 years ago • 3 comments

Bug Report

My block doesn't have any custom styling to go with it, so I've removed the .scss files:

https://github.com/Viper007Bond/syntaxhighlighter/tree/master/src

Expected Behavior

npm run build would generate blocks.build.js and that's it.

Actual Behavior

An error is thrown because the CSS file(s) don't exist.

 Let's build and compile the files...

✅   Built successfully!

fs.js:115
    throw err;
    ^

Error: ENOENT: no such file or directory, open '/mnt/c/work/wpdev/syntaxhighlighter/wordpress/wp-content/plugins/syntaxhighlighter/dist/blocks.editor.build.css'
    at Object.openSync (fs.js:436:3)
    at Object.readFileSync (fs.js:341:35)
    at getFileSize (/mnt/c/work/wpdev/syntaxhighlighter/wordpress/wp-content/plugins/syntaxhighlighter/node_modules/cgb-scripts/scripts/build.js:50:37)
    at compiler.run (/mnt/c/work/wpdev/syntaxhighlighter/wordpress/wp-content/plugins/syntaxhighlighter/node_modules/cgb-scripts/scripts/build.js:124:4)
    at emitRecords.err (/mnt/c/work/wpdev/syntaxhighlighter/wordpress/wp-content/plugins/syntaxhighlighter/node_modules/webpack/lib/Compiler.js:265:13)
    at Compiler.emitRecords (/mnt/c/work/wpdev/syntaxhighlighter/wordpress/wp-content/plugins/syntaxhighlighter/node_modules/webpack/lib/Compiler.js:371:38)
    at emitAssets.err (/mnt/c/work/wpdev/syntaxhighlighter/wordpress/wp-content/plugins/syntaxhighlighter/node_modules/webpack/lib/Compiler.js:258:10)
    at applyPluginsAsyncSeries1.err (/mnt/c/work/wpdev/syntaxhighlighter/wordpress/wp-content/plugins/syntaxhighlighter/node_modules/webpack/lib/Compiler.js:364:12)
    at next (/mnt/c/work/wpdev/syntaxhighlighter/wordpress/wp-content/plugins/syntaxhighlighter/node_modules/tapable/lib/Tapable.js:218:11)
    at Compiler.compiler.plugin (/mnt/c/work/wpdev/syntaxhighlighter/wordpress/wp-content/plugins/syntaxhighlighter/node_modules/webpack/lib/performance/SizeLimitsPlugin.js:99:4)

Steps to Reproduce

  1. Remove .scss file(s) from src directory.
  2. Run npm run build.

Real world example repository: https://github.com/Viper007Bond/syntaxhighlighter

  1. node -v: v10.14.1

  2. npm -v: 6.4.1

  3. yarn --version (if you use Yarn): 1.12.3 but not using Yarn in this case

  4. npm ls cgb-scripts (if you haven’t ejected): 1.13.0

  5. Operating system: Ubuntu 18.04.1 via WSL in Windows 10

Possible Solution

Perhaps the minification script or something comes along second and tries to access the CSS file but it doesn't exist because it wasn't needed? A file exists check might fix it?

Reproducible Demo

https://github.com/Viper007Bond/syntaxhighlighter

Viper007Bond avatar Dec 06 '18 23:12 Viper007Bond

Hi, I've got the same error. But I work with 2 blocks in 2 separate CGB project. One has ejected webpack configuration and the other not. With just common.scss, the second throw the error on build but not the first.

EDIT I eject CGB webpack configuration and I remove manually all configurations about styles. Work fine.

khylias avatar Jan 03 '20 13:01 khylias

Getting the same error, since I don't need any styles in my blocks. Can this be fixed? Putting the files back into their folders is not fixing this issue.

fabrikatdigital avatar Feb 17 '20 15:02 fabrikatdigital

As i see the issue is still opened. I have created a loophole, where i keep the files as empty, and ,most important ,keep the imports in the src/block/block.js

//  Import CSS.
import './editor.scss';
import './style.scss';

remove the calls in register_block_type and wp_register_style functions

all will be good when you try to build it.

edit : Also you must keep the common.scss file

Acika00mk avatar Apr 13 '20 20:04 Acika00mk