Skip to content

Cannot find module 'sinon' #3230

Closed
Closed

Description

@DannyDelott

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)

Activity

  1. tmcw commented on Sep 20, 2016

    @tmcw
    Contributor

    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?

  2. DannyDelott commented on Sep 20, 2016

    @DannyDelott
    ContributorAuthor

    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.

  3. mourner commented on Sep 20, 2016

    @mourner
    Member

    @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?

  4. DannyDelott commented on Sep 20, 2016

    @DannyDelott
    ContributorAuthor

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions