manuelmhtr / countries-and-timezones

Minimalistic library to work with countries and timezones data
MIT License
234 stars 68 forks source link

Error: Cannot find module './data' #7

Closed nlopin closed 5 years ago

nlopin commented 5 years ago

Hi!

After update to version 2, my app started to fail with the error:

Module not found: Error: Can't resolve './data' in 'projectname/node_modules/countries-and-timezones/src'
manuelmhtr commented 5 years ago

Hi @nlopin, That's weird, it should work. However, I would not recommend to require /data.

Since v2.0.0 data is a much simpler object (to make it 72% lighter), therefore some duplicated data was removed and object keys are not descriptive. However you can get a similar object by doing:

const ct = require('countries-and-timezones');
const data = {
  countries: ct.getAllCountries(),
  timezones: ct.getAllTimezones()
};
nlopin commented 5 years ago

I do not require /data it is required internally in the library. I'll investigate more

manuelmhtr commented 5 years ago

I see. Apparently is not a good practice to load json files with require. Could you try changing the file projectname/node_modules/countries-and-timezones/src/index.js

From:

const data = require('./data');

To

const data = require('./data.json');

If that works, could you tell me you node version and operative system?

Meanwhile I'll check the best practices to require json files.

manuelmhtr commented 5 years ago

According to documentation, require is designed to support JSON files as long as .json extension is used.

v2.0.3 should fix the issue.

nlopin commented 5 years ago

Thank you, 2.0.3 fixes the issue