Cheerio: Trouble loading 'package'

Created on 23 Mar 2016  ยท  2Comments  ยท  Source: cheeriojs/cheerio

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

Most helpful comment

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

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

All 2 comments

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")

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

//package.json
"jest": { 
  "moduleFileExtensions": [ 
    "json"
   ]
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

miguelmota picture miguelmota  ยท  3Comments

francoisromain picture francoisromain  ยท  5Comments

Canop picture Canop  ยท  3Comments

Tetheta picture Tetheta  ยท  3Comments

clayrisser picture clayrisser  ยท  4Comments