mxgraph icon indicating copy to clipboard operation
mxgraph copied to clipboard

mxgraph 3.7.3 fails to install using npm

Open daddyman opened this issue 9 years ago • 34 comments

npm install of mxgraph 3.7.3 fails during 'grunt build' in the postinstall. The error output is shown below.

The problem is that in the 3.7.3 release the javascript shipped under javascript/src/js is one big mxClient.js file instead of the individual files used in previous releases. The postinstall script runs grunt build which loads Gruntfile.js and tries to merge all of the javascript files into one file (dist/build.js) with a factory function to load it and export it . Line 14 of Gruntfile.js looks for the mxClient.include pattern in javascript/src/js/mxClient.js but doesn't find any and then tries to call map on undefined because the regular expression does not match anything.

My workaround for now is to stick with version 3.7.2-2 as my code relies on the factory that the grunt build wraps around the mxgraph javscript.

> [email protected] postinstall c:\dev\mx\mxweb\node_modules\mxgraph
> grunt build

Loading "Gruntfile.js" tasks...ERROR
>> TypeError: Cannot read property 'map' of null
Warning: Task "build" not found. Use --force to continue.

Aborted due to warnings.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules\chokidar\node_modules\
fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":
"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm ERR! code ELIFECYCLE
npm ERR! errno 3
npm ERR! [email protected] postinstall: `grunt build`
npm ERR! Exit status 3
npm ERR!
npm ERR! Failed at the [email protected] postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:

daddyman avatar Jun 27 '17 16:06 daddyman

Still broken in nodejs 4.4.7 and 6.11.4, npm 5.5.1 (and some older version I don't remember). Sad!

bbottema avatar Oct 20 '17 09:10 bbottema

This doesn't seem to fix the issue. We'll rehire the contractor who implemented the original NPM. As background, you probably noticed that we don't use NPM, nor understand its workings :).

davidjgraph avatar Dec 08 '17 16:12 davidjgraph

It works fine with npm 5.5.1 on mac.

hdev0301 avatar Dec 08 '17 17:12 hdev0301

I had a chance to look into the issue.

@daddyman mentioned that "The problem is that in the 3.7.3 release the javascript shipped under javascript/src/js is one big mxClient.js file instead of the individual files used in previous releases. The postinstall script runs grunt build which loads Gruntfile.js and tries to merge all of the javascript files into one file (dist/build.js) with a factory function to load it and export it . Line 14 of Gruntfile.js looks for the mxClient.include pattern in javascript/src/js/mxClient.js but doesn't find any and then tries to call map on undefined because the regular expression does not match anything.".

The tarballs published on npm registry seems to have different structure from the source of git repo. tarball has one single merged js file under /javascript/src/js, whereas the git contains separated files and folders under /javascript/js folder.

Possible solution:

  • Replacing all the tarballs to contain exactly same structure with the git source under /javascript/src/js folder.
  • Adding single line of validation code to gruntfile.js line 14.

Either case, it will require to replace all the tarballs since the version 3.7.3

witty3235 avatar Dec 08 '17 18:12 witty3235

We've made the dev repo public, it's at https://bitbucket.org/jgraph/mxgraph2.

In /etc/build there's the source Gruntfile.js, mxgraph-package.json, which becomes the package.json and the deploy script, deploy.sh, that we run when everything is building correctly.

Line 39 is where we publish to NPM. So the task (with Alon currently) is to work out how to change the Gruntfile in Bitbucket and then push both files to the correct locations.

davidjgraph avatar Dec 13 '17 15:12 davidjgraph

Does the current version here in Github work correctly?

davidjgraph avatar Dec 14 '17 13:12 davidjgraph

@davidjgraph it works with a source install from github npm install git+https://github.com/jgraph/mxgraph.git --save although some people have reported issues on windows systems, which I haven't had the time to test. But Linux and OSX are working as expected.

NicCOConnor avatar Dec 14 '17 15:12 NicCOConnor

Nice, thanks for the fixes. I'll close, if you have problems on windows please open a new ticket (and start working with a proper OS ;) )

davidjgraph avatar Dec 14 '17 15:12 davidjgraph

the same error, try the solution above, not work with [email protected]

JaniceLian avatar Dec 18 '17 10:12 JaniceLian

This error is still not solved. I encounter it with both npm 5.3 and 5.6.5 on linux. The issue appears to be grunt related. The current build system appears more then broken. I am counting just about 10 forks in the last few weeks that try to solve this issue and modernize the codebase. @davidjgraph Do you have a roadmap for the future of mxgraph? i.e. modernizing code base, migrating to a modern build system, transpilation, typings/Typescript, JSDoc/EsDoc instead of current documentation format? Do you need to maintain backwardscompatibility with global scoped variables our wouldn't it be time for mxGraph 4.0 with a modern import/export syntax?

I think given all the community interest and work put in you could make increadible progress on the codebase in no time if you accept corresponding pull requests.

lgleim avatar Jan 19 '18 14:01 lgleim

Our key is keeping mxGraph stable so we don't end up with a draw.io re-write to support all these changes.

We have none of those things on the roadmap (we don't have a roadmap) and the community needs to self-organise and implement themselves if these things are such an issue, we not going to do this. This is the whole point of open source :).

davidjgraph avatar Jan 19 '18 15:01 davidjgraph

I just cloned this repo, performed "npm install" in the root on a mac. The output reports success, so I assume that works. Do these step fail on Linux or were your steps different?

davidjgraph avatar Jan 20 '18 14:01 davidjgraph

So I spent some time on this recently. That method works. Doing a direct grunt build works. When it’s nested in another application’s package.json it has issues finding the npm grunt dependencies, almost as if the postinstall task is run before dependency’s are satisfied. It’s a weird and maddening bug, that had me stumped for a day with no resolution. I think the way forward may be to remove the postinstall grunt build process and just provide a dist.js. I have a need for this now so I may have a pull request on bitbucket soonish

Nic

On Jan 20, 2018, at 9:10 AM, David Benson [email protected] wrote:

I just cloned this repo, performed "npm install" in the root on a mac. The output reports success, so I assume that works. Do these step fail on Linux or were your steps different?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

NicCOConnor avatar Jan 20 '18 17:01 NicCOConnor

There was an error with the deploy step from BB, fixed with https://bitbucket.org/jgraph/mxgraph2/commits/c9df1b8225ce59010b0ae65b95d385f6d8efb7a7. The directory didn't get created so the Github release didn't the grunt file in etc/build originally.

I don't know the mechanics of npmjs, whether a copy is made at publish time, etc. Maybe I'll try having the gruntfile in both the root and etc/build and see if that works.

davidjgraph avatar Jan 20 '18 18:01 davidjgraph