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

Cannot find module 'sinon' #3230

Closed
DannyDelott opened this issue Sep 20, 2016 · 4 comments
Closed

Cannot find module 'sinon' #3230

DannyDelott opened this issue Sep 20, 2016 · 4 comments

Comments

@DannyDelott
Copy link
Contributor

DannyDelott commented Sep 20, 2016

As of 0.24.0, sinon appears to be used outside of the testing environment:

var sinon = require('sinon');

This causes an issue with npm install mapbox-gl, because devDependencies are not installed with this command without explicitly using the --dev flag.

With webpack, this results in the following stack trace:

Error: Cannot find module 'sinon'
    at Function.Module._resolveFilename (module.js:440:15)
    at Function.Module._load (module.js:388:25)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/code/node_modules/mapbox-gl/js/util/window.js:5:13)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/code/node_modules/mapbox-gl/js/util/browser.js:8:14)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/code/node_modules/mapbox-gl/js/mapbox-gl.js:3:15)
@tmcw
Copy link
Contributor

tmcw commented Sep 20, 2016

Two issues layered here:

because devDependencies are not installed with this command without explicitly using the --dev flag.

This isn't technically true. By default, npm does install devDependencies: it's likely that you have NODE_ENV=production set globally, which is relatively uncommon.

Are you using something similar to the suggested webpack configuration?

@DannyDelott
Copy link
Contributor Author

Thanks, we are using the suggested webpack config (it's great!) and haven't configured a production env yet, so that hasn't happened yet.

Are you sure about devDependencies? According to this answer on SO:

npm install "$package"
In that case, you normally don't want the development dependencies, so you just get what is needed to use the package: dependencies.

If you really want to install development packages in that case, you can set the dev config option to true, possibly from the command line as:

npm install "$package" --dev
The option is false by default since this is a much less common case.

@mourner
Copy link
Member

mourner commented Sep 20, 2016

@tmcw npm install in a mapbox-gl dir installs dev deps of mapbox-gl, but npm install mapbox-gl in a different dir does not.

@DannyDelott would this solution be acceptable to you?

@DannyDelott
Copy link
Contributor Author

DannyDelott commented Sep 20, 2016

@mourner I need sinon in my project anyway, so this is a motivation to refactor some home-rolled spies now instead of needing a workaround.

Just wanted to document it here in case others aren't using sinon and have trouble with the new release.

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