Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-running r.js gives parse error for first dependency #182

Closed
webpro opened this issue Jun 5, 2012 · 4 comments
Closed

Re-running r.js gives parse error for first dependency #182

webpro opened this issue Jun 5, 2012 · 4 comments

Comments

@webpro
Copy link

webpro commented Jun 5, 2012

When re-running r.js with the configured output dir not being empty (i.e. when running r.js without first removing this directory), I get the following error:

Tracing dependencies for: main
Error: Parse error using UglifyJS for file: [...]/src-build/js/app.js
Unexpected token: eof (undefined) (line: 1, col: 55, pos: 55)

Error
    at new JS_Parse_Error ([...]/r.js:9633:22)

In module tree:
    main

When I simply remove the output directory first, everything runs fine. Perhaps best to simply remove/empty the directory before tracing dependencies. (Although this could actually be another, more serious bug.)

@jrburke
Copy link
Member

jrburke commented Jun 8, 2012

Do you have a test case I can try? I tried with a simpler project here, but I do not see the issue. I think it may be related to how uglify uglifies the code the first time. Feel free to pass it to me off list if it should be private.

@pixelhandler
Copy link

jrburke, I think I have a similar issue and do have a test project, see : #187

-Bill

@webpro
Copy link
Author

webpro commented Jun 9, 2012

Apologies for not being more thorough initially.

First of all, it seems wrong to me to trace module dependencies using the uglified files in the output folder of a previous run. Maybe this is for performance reasons?

Second, this configuration I added led to identifying the issue:

"onBuildRead": function(moduleName, path, contents) {
    return contents.replace(/console\.(.*)/g, '');
}

The first time I run r.js, the contents enter this function unoptimized, but the second time, contents is uglified. Imho, the code should never be uglified until after "onBuildRead".

(So after the first run, with this configuration I have, the contents is already uglified before this function is called. And my regexp strips the rest of the lines having "console.", which now contains more code.)

The problem in the end is (besides my error-prone regexp) that this function is executed using different code (in first vs. consecutive runs).

Let me know if you still need a test case.

Edit: I'm also willing to dive into your sources and offer a pull request.

@jrburke
Copy link
Member

jrburke commented Jun 9, 2012

@webpro thanks for the extra info. Your feedback has brought me around to by default removing the build dir before each build run, and have an opt in option to keep it. I think more people are hitting this issue now that the onBuild* processors are available. I opened #191 to track the specific code change now that we have identified a path for it.

@pixelhandler I will follow up in #187 on that issue. Thanks for the repo that I can pull to try out the problem, I will be doing that shortly.

I'll close this bug now that we have the more targeted #191, and I'll follow up in #187 separately. Put a comment in #191 if you want to get notified when it is fixed so that you can try out the r.js snapshot that will go with the fix.

@jrburke jrburke closed this as completed Jun 9, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants