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

Closed
paulmcfe opened this Issue Jul 21, 2016 · 7 comments

Projects

None yet

3 participants

@paulmcfe
paulmcfe commented Jul 21, 2016 edited

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
Member

Are you sure that's with v1.0.2?

@paulmcfe

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
Member

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
#666 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAVVtTbBuWMf1faicTAtffGrpLtDYLgeks5qX-MogaJpZM4JRsOz
.

@paulmcfe

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

@XhmikosR
Member

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
codemirror/CodeMirror@8a1dd16


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#666 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAVVtUVm-ocrFZtTa42GRjmlYeAhLzsqks5qYJohgaJpZM4JRsOz
.

@orionlee
Contributor

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
Member

@orionlee: Please submit a PR and CC me.

@orionlee orionlee added a commit to orionlee/csslint that referenced this issue Aug 25, 2016
@orionlee orionlee Fix #666 : Make core (dist/csslint.js) compatible with CodeMirror in …
…browser,

- in general, any environment that supports CommonJS module,
  and expect proper module, exports global
4764627
@XhmikosR XhmikosR closed this in #672 Sep 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment