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

Missing jsdom dependencies for dist/node/* stuffs? #1347

Open
pm5 opened this issue Jun 20, 2017 · 6 comments
Open

Missing jsdom dependencies for dist/node/* stuffs? #1347

pm5 opened this issue Jun 20, 2017 · 6 comments

Comments

@pm5
Copy link

pm5 commented Jun 20, 2017

I get the following error if I include paper-jsdom 0.11.4 in a project that is already using jsdom 11.0.0:

> var paper = require('paper-jsdom');
TypeError: jsdom.jsdom is not a function
    at Object.<anonymous> (/Users/pm5/src/code/n/node-paper/sandbox/node_modules/paper/dist/node/self.js:40:26)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/pm5/src/code/n/node-paper/sandbox/node_modules/paper/dist/paper-full.js:35:16)
    at Object.<anonymous> (/Users/pm5/src/code/n/node-paper/sandbox/node_modules/paper/dist/paper-full.js:16486:3)

I think the reason for that is Paper.js, specifically things under dist/node, are using jsdom ^9.4.0, but jsdom is a devDependency so it is not installed, and the top-level jsdom (which is 11.0.0 in my case) will be used.

You can reproduce the error with:

$ npm init -y
$ npm i jsdom@11
$ npm i paper-jsdom
$ node
> var paper = require('paper-jsdom');

I'm not familiar with Paper.js build pipeline so I'm not sure if the better course of action is to bundle jsdom for dist/node or to just move jsdom to dependency (which I think Paper.js is trying to avoid having any).

@lehni
Copy link
Member

lehni commented Jun 21, 2017

jsdom is a dependency of the paper-jsdom package, not a dev-dependency. If you don't install your own version of jsdom, then things should work out fine. paper.js has not yet been tested against jsdom v10 & v11...

@pm5
Copy link
Author

pm5 commented Jun 21, 2017

But shouldn't there be some way for Paper.js to use its own jsdom regardless of project requirements? I understand that things would work out fine if my project is not installing jsdom, but if I'm using some other modules that require jsdom v11 then that would need some dependency order tweaking to make it work, and could be hard to debug.

@lehni
Copy link
Member

lehni commented Jun 21, 2017

I guess this is a short-coming of using the shim-package approach described here:

#1252 (comment)

The problem I believe is that the dependency is of the paper-jsdom package, not the parent paper package, but it is paper that requires jsdom, so you end up with the wrong version in your scenario.

This would be easy to fix if paper.js only existed for node.js. But we're dealing with rather complex hybrid scenarios, and I haven't found an approach that makes everybody happy yet...

Perhaps there's a way to have paper-jsdom require jsdom and pass it on to paper

@lehni
Copy link
Member

lehni commented Jun 21, 2017

But the easier fix is probably simply to get paper.js working with jsdom 11

@lehni
Copy link
Member

lehni commented Jun 21, 2017

There is an issue unfortunately that is blocking jsdom v10 & v11 for us:

jsdom/jsdom#1816 (comment)

@HriBB
Copy link
Contributor

HriBB commented Jun 11, 2018

I have a very similar error. I am bundling paper/dist/paper-core with webpack, and doing server side rendering with react. When I try to load the bundle, I get the first error:

TypeError: Cannot read property 'parent' of undefined
    at Object.eval (webpack:///./node_modules/paper/dist/node/self.js?:20:28)
    at eval (webpack:///./node_modules/paper/dist/node/self.js?:62:30)
    at Object../node_modules/paper/dist/node/self.js (/home/bojan/www/climbuddy/client/server/map.bundle.js:34531:1)
    at __webpack_require__ (/home/bojan/www/climbuddy/client/server/map.bundle.js:26:30)
    at Object.eval (webpack:///./node_modules/paper/dist/paper-core.js?:35:16)
    at eval (webpack:///./node_modules/paper/dist/paper-core.js?:14798:3)
    at Object../node_modules/paper/dist/paper-core.js (/home/bojan/www/climbuddy/client/server/map.bundle.js:34553:1)
    at __webpack_require__ (/home/bojan/www/climbuddy/client/server/map.bundle.js:26:30)
    at eval (webpack:///./node_modules/react-paper-bindings/lib/View.js?:15:18)
    at Object../node_modules/react-paper-bindings/lib/View.js (/home/bojan/www/climbuddy/client/server/map.bundle.js:37188:1)

If I manually fix the node_modules/paper.js/dist/node/self.js to check for the presence of the module.parent, the error goes away:

var parent = module.parent ? module.parent.parent : null,

but then I get a second error, same as @pm5:

TypeError: jsdom.jsdom is not a function
    at Object.<anonymous> (/home/bojan/www/climbuddy/client/server/map.bundle.js:264508:26)
    at Object../node_modules/paper/dist/node/self.js (/home/bojan/www/climbuddy/client/server/map.bundle.js:264530:30)
    at __webpack_require__ (/home/bojan/www/climbuddy/client/server/map.bundle.js:26:30)
    at Object.<anonymous> (/home/bojan/www/climbuddy/client/server/map.bundle.js:264626:16)
    at Object../node_modules/paper/dist/paper-core.js (/home/bojan/www/climbuddy/client/server/map.bundle.js:279389:3)
    at __webpack_require__ (/home/bojan/www/climbuddy/client/server/map.bundle.js:26:30)
    at Object../node_modules/react-paper-bindings/lib/View.js (/home/bojan/www/climbuddy/client/server/map.bundle.js:311955:18)
    at __webpack_require__ (/home/bojan/www/climbuddy/client/server/map.bundle.js:26:30)
    at Object../node_modules/react-paper-bindings/lib/index.js (/home/bojan/www/climbuddy/client/server/map.bundle.js:312128:13)
    at __webpack_require__ (/home/bojan/www/climbuddy/client/server/map.bundle.js:26:30)

because one of my other dependencies (maybe jest) requires a newer version of jsdom.

After looking at the source code, I managed to find a hacky solution for my use case. In my server entry, I add a global.self variable, that is later used by paper.js at initialization:

// paper.js ssr fix
global.self = {
  navigator: {
    userAgent: `Node.js (${process.platform}; U; rv:${process.version})`
  }
}

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