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

jsep is undefined fix #5601

Merged
merged 5 commits into from
Jul 10, 2017
Merged

jsep is undefined fix #5601

merged 5 commits into from
Jul 10, 2017

Conversation

ggetz
Copy link
Contributor

@ggetz ggetz commented Jul 7, 2017

Fixes #5593

Fixes the jsep is undefined error that was occurring when using webpack. Tested using the configuration @lucastheisen provided in #5593

@lilleyse Can you review please?

@pjcozzi
Copy link
Contributor

pjcozzi commented Jul 7, 2017

@ggetz please update CHANGES.md.

@lucastheisen can you confirm that this fixes your issue?

@lilleyse
Copy link
Contributor

lilleyse commented Jul 7, 2017

This fixes the Node issues I was having. 👍

@ggetz
Copy link
Contributor Author

ggetz commented Jul 7, 2017

Updated CHANGES.md

@lucastheisen
Copy link

My test would be using the example that @ggetz mentioned she confirmed this fix with. However, I would be happy to also test against my real project if there is a relatively straightforward path to doing so... Do you guys have a CI build that would allow me to point to this fix? Or do I need to build from from the pull request source branch and build myself? I'll do the legwork, just curious as to the best approach...

@lucastheisen
Copy link

lucastheisen commented Jul 7, 2017

As far as I can tell, the jsep stuff gets embedded into the cesium js files during the build (in the build folder there is no jsep under ThirdParty). This means i cant just swap out a file to test, so I need to build. However, my corporate environment is a major pain in the neck... the npm install fails due to our wonky ssl inspection stuff... I'll keep trying, and let you know if i am able to get this going.

@lucastheisen
Copy link

Okay, after an RTFM moment, I checked out the @ggetz branch, then ran npm install; npm run release. Next I updated my package.json to use a local dependency, and was able to verify that I no longer get a jsep error. That said, now i get this one again:

18:41:46.831 Error: Cesium missing ThirdParty/pako_inflate 1 app.js:4383:27
	main http://localhost:8080/app.js:4383:27
	callDep http://localhost:8080/app.js:4245:13
	main http://localhost:8080/app.js:4378:31
	req http://localhost:8080/app.js:4452:13
	<anonymous> http://localhost:8080/app.js:228984:1
	<anonymous> http://localhost:8080/app.js:4069:2
	<anonymous> http://localhost:8080/app.js:4047:29
	__webpack_require__ http://localhost:8080/app.js:20:12
	<anonymous> http://localhost:8080/app.js:3844:1
	__webpack_require__ http://localhost:8080/app.js:20:12
	<anonymous> http://localhost:8080/app.js:234662:18
	__webpack_require__ http://localhost:8080/app.js:20:12
	<anonymous> http://localhost:8080/app.js:66:18
	<anonymous> http://localhost:8080/app.js:1:11

Which appears to have reared its ugly head again in 1.34. Guess I will wait for a patch for that and try again...

Thanks for getting this one sorted out!

@hpinkos
Copy link
Contributor

hpinkos commented Jul 10, 2017

We should avoid directly modifying third party files. It can be a pain when we go to update that file in the future. @mramato do you have any suggestions for working around this in a different way?

@ggetz
Copy link
Contributor Author

ggetz commented Jul 10, 2017

Thanks for testing this out @lucastheisen, hopefully we can get #5417 sorted soon.

@hpinkos I beleive @lilleyse said we already have modified this file, if that changes anything at all.

@hpinkos
Copy link
Contributor

hpinkos commented Jul 10, 2017

See this PR: #5365
I'm fairly certain that stripping out this code is not the right solution here based on the changes @mramato made in that PR

@ggetz
Copy link
Contributor Author

ggetz commented Jul 10, 2017

Would a better fix maybe be to define jsep.noConflict for node environments as well?

@mramato
Copy link
Contributor

mramato commented Jul 10, 2017

I think the correct fix is to put all of the old code back and only call jsep.noConflict() at the end if (typeof jsep.noConflict === 'function)

@ggetz
Copy link
Contributor Author

ggetz commented Jul 10, 2017

Updated

@lilleyse
Copy link
Contributor

The recent changes don't work from the Node side because jsep itself is undefined.

$ node -e "var test = require('gltf-pipeline');"
C:\Users\slilley\Desktop\asdf\node_modules\cesium\Source\ThirdParty\jsep.js:683
    if (typeof jsep.noConflict === 'function') {
               ^

ReferenceError: jsep is not defined
    at C:\Users\slilley\Desktop\asdf\node_modules\cesium\Source\ThirdParty\jsep.
js:683:16
    at Object.execCb (C:\Users\slilley\Desktop\asdf\node_modules\requirejs\bin\r
.js:1946:33)
    at Object.check (C:\Users\slilley\Desktop\asdf\node_modules\requirejs\bin\r.
js:1133:51)
    at Object.enable (C:\Users\slilley\Desktop\asdf\node_modules\requirejs\bin\r
.js:1426:22)
    at Object.init (C:\Users\slilley\Desktop\asdf\node_modules\requirejs\bin\r.j
s:1038:26)
    at callGetModule (C:\Users\slilley\Desktop\asdf\node_modules\requirejs\bin\r
.js:1453:63)
    at Object.completeLoad (C:\Users\slilley\Desktop\asdf\node_modules\requirejs
\bin\r.js:1840:21)
    at Function.req.load (C:\Users\slilley\Desktop\asdf\node_modules\requirejs\b
in\r.js:2613:17)
    at Object.load (C:\Users\slilley\Desktop\asdf\node_modules\requirejs\bin\r.j
s:1935:21)
    at Object.load (C:\Users\slilley\Desktop\asdf\node_modules\requirejs\bin\r.j
s:1084:29)
    at Object.fetch (C:\Users\slilley\Desktop\asdf\node_modules\requirejs\bin\r.
js:1074:66)

@ggetz
Copy link
Contributor Author

ggetz commented Jul 10, 2017

@mramato Is exports.parse = jsep; supposed to be exports.jsep = jsep?

@mramato
Copy link
Contributor

mramato commented Jul 10, 2017

@mramato Is exports.parse = jsep; supposed to be exports.jsep?

That branch should never be executed the exports = module.exports = jsep; is what should be getting executed.

@lilleyse what do I need to do to reproduce this in gltf-pipeline?

@lilleyse
Copy link
Contributor

I am preparing a gltf-pipeline release with npm pack npm install --production <tarball> and calling node -e "var test = require('gltf-pipeline');"

@mramato
Copy link
Contributor

mramato commented Jul 10, 2017

Thanks, I can reproduce without the pack and install parts by just requiring in gltf-pipeline.

I see what the problem is:

  1. jsep gets declared as a local in the IIFE
  2. In the browser, this also becomes a global, and noConflict removes the global.
  3. In Node, the global is never created so jsep is undefined, leading to an except even checking for its existence.

@@ -680,5 +680,9 @@ define(function() {
}
}(this));

return jsep.noConflict();
if (typeof jsep.noConflict === 'function') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this to if (typeof jsep !== 'undefined') { and remove the last return statement on line 687. I think that will finally do it. Add a comment to the if that mentions that jsep only exists when running in a browser, not Node.

@mramato
Copy link
Contributor

mramato commented Jul 10, 2017

What's even weirder is that in some cases, jsep is defined, even in node, and has the noConflict function. I think there's some odd side-effects going on here with loading jsep via requirejs in Node and that's the root cause of the issue. I think the above suggested changes should resolve things on the Node side for now (not sure about webpack).

When we to ES6, we'll have to revisit our strategy for how we wrap/use third party libraries.

@mramato
Copy link
Contributor

mramato commented Jul 10, 2017

Doc is failing, which is why travis is failing, but it doesn't appear to be related to this branch. @lilleyse can you test this out. Thanks.

@ggetz
Copy link
Contributor Author

ggetz commented Jul 10, 2017

I tested with webpack and it works. I'm not sure why the build is failing on makeZipFile though, the command runs without error locally.

@lilleyse
Copy link
Contributor

The latest changes work for me.

@mramato
Copy link
Contributor

mramato commented Jul 10, 2017

Thanks @ggetz!

@mramato mramato merged commit 12e1d6d into CesiumGS:master Jul 10, 2017
@mramato mramato deleted the define-jsep branch July 10, 2017 20:14
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

Successfully merging this pull request may close these issues.

7 participants