Closed akoenig closed 9 years ago
Ah ok. these should never be called by the application when its running its purely there to compute code coverage. What would be required. Just the empty folder or the files as well? I currently specifically add that folder to the .gitignore atm.
Is there someway to ignore this require statement in browserfy or copy a blank index.js into the folder before running?
I created a fork to browserify this module : https://github.com/Wilkins/gpx-parse I had to hack the browserify configuration so simulate a fake lib-cov module. It's working pretty nicely up to now. If you guys can test it to confirm everything is ok. The resulting JS code is pretty huge though : 400kB.
Is this something you could wrap up in a pull request or explain so I can add to the project as this has come up a few times before.
Regarding the large file size - I'm guessing there is a reasonable amount of unexecuted js wrapped up in that file too that could be removed and the file could also be minified or is that post minification size?
Done in this PR : https://github.com/elliotstokes/gpx-parse/pull/8 The result file of 400kB is before minification. The minified version is about 150kB.
Fixed by #8
@elliotstokes I just installed gpx-parse and had the same error using npm install gpx-parse
.
When I run browserify I get the following error:
Error: Cannot find module './lib-cov/gpx-parse' from 'somewhere\node_modules\gpx-parse'
I add it to my .js like this:
var gpxParse = require('gpx-parse');
Really? Did you run
npm run browserify
I just tried and it was successful here. The dist folder should contain the latest browserified version if you are having issues.
Essentially what I' doing is adding an alias within the grunt task.
dist: {
src: 'index.js',
dest: 'dist/gpx-parse-browser.js',
options: {
alias: [
// Mockup to avoid loading lib-cov/gpx-parse in the browserify build process
'./browserify-mock.js:./lib-cov/gpx-parse'
]
}
}
Open to other suggestions though if you have any.
@elliotstokes Running it for your repository works for me. But when I install it and add it with the above require statement to my js and run browserify on my js I get that exception.
@elliotstokes I want to add gpx-parse to my existing js. To build my js I use browserify.
I add gpx-parse to my js using: var gpxParse = require('gpx-parse');
I build the js using: browserify js/main-template.js -o js/main.js
This produces the following exception:
Error: Cannot find module './lib-cov/gpx-parse' from 'C:\workspace\project\node_modules\gpx-parse'
at C:\workspace\project\node_modules\browserify\node_modules\resolve\lib\async.js:55:21
at load (C:\workspace\project\node_modules\browserify\node_modules\resolve\lib\async.js:69:43)
at onex (C:\workspace\project\node_modules\browserify\node_modules\resolve\lib\async.js:92:31)
at C:\workspace\project\node_modules\browserify\node_modules\resolve\lib\async.js:22:47
at FSReqWrap.oncomplete (fs.js:82:15)
When I run npm run browserify
from C:\workspace\project\node_modules\gpx-parse
this works and generates the js in the dist folder.
You need to set up an alias for the missing file and use the browserify-mock.js file instead. I'm doing it with gulp in my build. I'm not sure of the correct parameters on the browserify cli.
@elliotstokes Thanks. I tried with aliasify, but wasn't able to do it. For now I just changed the require statement in your index.js. I might try again in the future.
Thanks for your work and your help!
Hey Elliot,
thanks for writing and sharing
gpx-parse
. Works great in Node.js!I tried to
browserify
your module so that I can use it in the browser as well without any API modifications. Unfortunately that did not work. There are missing source files in the repository. The culprit is the ternary operator within index.js.Browserify fails here because it seeks for all
require
statements in order to embed the dependencies. The firstrequire
statement imports a module which does not exist in the source tree. Is this intended? This statement will also fail in a Node.js environment if the respective environment variable is set.Maybe we could commit a skeleton directory which emulates that what will be injected by
jscoverage/JSCover
./André