question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Having a non-breaking space in css leads to error

See original GitHub issue

Environment

Using clean-css through Angular CLI 1.7.0 which moved to clean-css. clean-css is imported through webpack plugin as it can seen here: https://github.com/angular/angular-cli/blob/master/packages/@angular/cli/plugins/cleancss-webpack-plugin.ts

Configuration options

 const cleancss = new CleanCSS({
          compatibility: 'ie9',
          level: 2,
          inline: false,
          returnPromise: true,
          sourceMap: this._options.sourceMap,
        });

Input SCSS

Image, since non-breaking space would not show up properly (screenshot taken on VSCode on faulty scss code, with Highlight bad characters VSCode plugin):

bad_char

This code was transpiled to CSS, which still contains the non-breaking space. Resulting in following error.

Error

/project/node_modules/clean-css/lib/reader/input-source-map-tracker.js:37 if (originalPosition.line === null && line > 1 && selectorFallbacks > 0) {

TypeError: Cannot read property ‘line’ of undefined at originalPositionFor (/project/node_modules/clean-css/lib/reader/input-source-map-tracker.js:37:24) at originalMetadata (/project/node_modules/clean-css/lib/tokenizer/tokenize.js:486:43) at intoTokens (/project/node_modules/clean-css/lib/tokenizer/tokenize.js:435:68) at tokenize (/project/node_modules/clean-css/lib/tokenizer/tokenize.js:74:10) at fromStyles (/project/node_modules/clean-css/lib/reader/read-sources.js:147:12) at fromString (/project/node_modules/clean-css/lib/reader/read-sources.js:48:10) at doReadSources (/project/node_modules/clean-css/lib/reader/read-sources.js:33:12) at readSources (/project/node_modules/clean-css/lib/reader/read-sources.js:24:10) at /project/node_modules/clean-css/lib/clean.js:99:12 at _combinedTickCallback (internal/process/next_tick.js:131:7) at process._tickCallback (internal/process/next_tick.js:180:9)

Expected behavior

Presence of non-breaking space should not block the production of css since these kind of spaces should be deleted in the minification process.

Potential fix

We could add a marker for no-break space and replace the character with standard space.

NO_BREAK_SPACE: /\u00A0|\u202F|\uFEFF/g,

then in tokenize:

isNoBreakSpace = Marker.NO_BREAK_SPACE.test(character);
...
else if (isNoBreakSpace) {
      // Replace any kind of no-break-space with standard space
      character = Marker.SPACE;
      buffer.push(character);
    }

Can’t open a PR as I don’t know how to test that in your test suit.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:17
  • Comments:27

github_iconTop GitHub Comments

13reactions
tx8821commented, Feb 27, 2018

Please fix this! Angular CLI cant build because of this!

4reactions
scotecommented, Mar 3, 2018

@barocsi @blackholegalaxy for me the error came from a third party lib (materialize-css) i’m using in my project. I can’t update those css or scss file.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Having a non-breaking space in css leads to error · Issue #1006
Presence of non-breaking space should not block the production of css since these kind of spaces should be deleted in the minification process....
Read more >
nbsp not working in CSS content tag [duplicate] - Stack Overflow
Fixed it by copying and pasting the non-breaking space from character map into my code editor.
Read more >
How to Add a Non-breaking Space with the   Character ...
First, What Are Character Entities? ... Character entities are reserved for displaying various characters in the browser. For instance, the less ...
Read more >
&nbsp and HTML Space Challenges and Tricks | Mailtrap Blog
Nbsp stands for non-breaking space, meaning that strings separated with this entity will not be separated and put into separate lines.
Read more >
Non-Breaking Space in HTML
The non-breaking space can be used to create white space between web page elements. In our example above with the pictures, white space...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found