CSSLint / csslint

Automated linting of Cascading Stylesheets
http://csslint.net
Other
4.77k stars 483 forks source link

Including csslint.js causes "require is not defined" errors #666

Closed paulmcfe closed 7 years ago

paulmcfe commented 8 years ago

I've been using csslint.js in a CodeMirror project for several months without a problem. A few days ago, I started getting "Uncaught ReferenceError: require is not defined" messages. After some trial and error, I found that if I remove csslint.js, the errors go away. Here are my includes:

<script src="http://htmlhint.com/js/htmlhint.js"></script>
<script src="http://csslint.net/js/csslint.js"></script>
<script src="js/lint/lint.js"></script>
<script src="js/lint/html-lint.js"></script>
<script src="js/lint/css-lint.js"></script>
<script src="js/spectrum.js"></script>

The errors:

image

Perhaps a recent commit is causing the error?

Cheers, Paul

XhmikosR commented 8 years ago

Are you sure that's with v1.0.2?

paulmcfe commented 8 years ago

Yes. I'm linking directly to csslint.js on csslint.net. I also tried downloading v1.0.2 and including the local copy instead of the remote file, but I received the same errors.

XhmikosR commented 8 years ago

Try 1.0.1. Also do not rely on our website for your assets. It's bad practice.

On Jul 22, 2016 00:22, "Paul McFedries" notifications@github.com wrote:

Yes. I'm linking directly to csslint.js on csslint.net. I also tried downloading v1.0.2 and including the local copy instead of the remote file, but I received the same errors.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/CSSLint/csslint/issues/666#issuecomment-234388238, or mute the thread https://github.com/notifications/unsubscribe-auth/AAVVtTbBuWMf1faicTAtffGrpLtDYLgeks5qX-MogaJpZM4JRsOz .

paulmcfe commented 8 years ago

Understood, thanks. 1.0.1 did not solve the problem. See also this CodeMirror issue, which seems to be the same problem:

https://github.com/codemirror/CodeMirror/commit/8a1dd1604974840fe69163f958ad204010442aea

XhmikosR commented 8 years ago

There nothing I can do since the Web build works on our site.

You are welcome to make a pull request and CC me if you find fix. Have a look at parser lib too.

On Jul 22, 2016 13:23, "Paul McFedries" notifications@github.com wrote:

Understood, thanks. 1.0.1 did not solve the problem. See also this CodeMirror issue, which seems to be the same problem:

codemirror/CodeMirror@8a1dd16 https://github.com/codemirror/CodeMirror/commit/8a1dd1604974840fe69163f958ad204010442aea

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/CSSLint/csslint/issues/666#issuecomment-234509679, or mute the thread https://github.com/notifications/unsubscribe-auth/AAVVtUVm-ocrFZtTa42GRjmlYeAhLzsqks5qYJohgaJpZM4JRsOz .

orionlee commented 8 years ago

I ran into the same problem. It is in the generated dist/csslint.js , it defines dummy module and exports in global scope, rather than inside CSSLint definition.

It breaks integration with CodeMirror (and possibly other web js lib supporting module loading) because the dummy module and exports make CodeMirror mistakenly believe it is loaded in CommonJS environment.

One way to fix it is to change the Gruntefile and move the dummy module and exports inside CSSLint definition.

Thought?

XhmikosR commented 8 years ago

@orionlee: Please submit a PR and CC me.