Got: const pkg = require('./package');

Created on 22 Jan 2017  路  4Comments  路  Source: sindresorhus/got

v6.7.1

const pkg = require('./package');

this line is causing issue. "package" is not defined in package.json

ERROR in ./~/is-online/~/is-reachable/~/got/index.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./package in /Users/alan/Desktop/Electron/app/node_modules/is-online/node_modules/is-reachable/node_modules/got
resolve file
/Users/alan/Desktop/Electron/app/node_modules/is-online/node_modules/is-reachable/node_modules/got/package doesn't exist
/Users/alan/Desktop/Electron/app/node_modules/is-online/node_modules/is-reachable/node_modules/got/package.js doesn't exist
/Users/alan/Desktop/Electron/app/node_modules/is-online/node_modules/is-reachable/node_modules/got/package.jsx doesn't exist
resolve directory

Most helpful comment

I leave that here because it can help people facing similar issue.

I was having an issue with the got module (through vue-resource) like this:

ERROR in ./~/got/index.js
Module not found: Error: Can't resolve './package' in '/path/to/project/node_modules/got'

I found that the issue was caused by webpack not resolving the extension automatically, so I added this to my webpack.config.js file:

resolve: {
    extensions: ['.js', '.json']
}

so now I can omit the .json extension when I require() a module.

Hope this helps someone :)

All 4 comments

package is package.json. Extensions are optional.

I leave that here because it can help people facing similar issue.

I was having an issue with the got module (through vue-resource) like this:

ERROR in ./~/got/index.js
Module not found: Error: Can't resolve './package' in '/path/to/project/node_modules/got'

I found that the issue was caused by webpack not resolving the extension automatically, so I added this to my webpack.config.js file:

resolve: {
    extensions: ['.js', '.json']
}

so now I can omit the .json extension when I require() a module.

Hope this helps someone :)

@hugohil Sir, you helped me a lot with this, i was having this './package' error, and your fix solved it!

_I leave that here because it can help people facing similar issue._

I was having an issue with the got module (through vue-resource) like this:

ERROR in ./~/got/index.js
Module not found: Error: Can't resolve './package' in '/path/to/project/node_modules/got'

I found that the issue was caused by webpack not resolving the extension automatically, so I added this to my webpack.config.js file:

resolve: {
    extensions: ['.js', '.json']
}

so now I can omit the .json extension when I require() a module.

Hope this helps someone :)

i am facing same issue, but i didnt have webpack file in my project, so please give appropriate solution

Was this page helpful?
0 / 5 - 0 ratings

Related issues

joolfe picture joolfe  路  3Comments

sindresorhus picture sindresorhus  路  3Comments

jamestalmage picture jamestalmage  路  3Comments

khizarsonu picture khizarsonu  路  3Comments

dAnjou picture dAnjou  路  3Comments