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

Trouble loading 'package' #836

Closed
note89 opened this issue Mar 23, 2016 · 2 comments
Closed

Trouble loading 'package' #836

note89 opened this issue Mar 23, 2016 · 2 comments

Comments

@note89
Copy link

note89 commented Mar 23, 2016

i had to change
exports.version = require('./package').version;
to
exports.version = require('./package.json').version;
in
https://github.com/cheeriojs/cheerio/blob/master/index.js

Otherwise i got this error

Using Jest CLI v0.9.2, jasmine2, babel-jest
 FAIL  __tests__/components/CoolComponent.js
● Runtime Error
Error: Cannot find module './package' from 'index.js'
    at Loader._resolveNodeModule (/home/nils/Programmering/relay/phoenix-hipster-stack/node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:431:11)
    at Object.<anonymous> (/home/nils/Programmering/relay/phoenix-hipster-stack/node_modules/cheerio/index.js:11:19)
    at Object.<anonymous> (/home/nils/Programmering/relay/phoenix-hipster-stack/node_modules/enzyme/build/ReactWrapper.js:13:16)

Running Ubuntu 15.10

@ItsCosmo
Copy link

ItsCosmo commented Apr 4, 2016

If you are using webpack, you can work around this issue by putting in the following plugin configuration:

plugins: [
    // other plugins that you need
    new NormalModuleReplacementPlugin(/^\.\/package$/, function(result) {
        if(/cheerio/.test(result.context)) {
            result.request = "./package.json"
        }
    })
]

This looks for any require("./package") in the cheerio module path, and replaces it with require("./package.json")

@ttrmw
Copy link

ttrmw commented Apr 8, 2016

It's also possible to work around this with Jest's configuration:

//package.json
"jest": { 
  "moduleFileExtensions": [ 
    "json"
   ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants