Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Module not found when using import instead of require

I am trying to use import instead of require for all modules in my project, but some older npm modules only have instructions for require.

In the case of 'isomorphic-fetch' I can't find the proper way to use import:

works

require('isomorphic-fetch')

fails

import 'isomporphic-fetch'   
import Something from 'isomorphic-fetch'

// error Can't resolve 'isomporphic-fetch' from Project/src/js/

Converting to import does work with the es6-promise module.

works

require('es6-promise').polyfill()

works

import Something from 'es6-promise'
Something.polyfill()
like image 939
Kokodoko Avatar asked Nov 27 '25 01:11

Kokodoko


1 Answers

Since import does work with other modules, and require('isomorphic-fetch') works, it's probably a named export problem.

Try import * as Something from 'isomorphic-fetch'

If that works, it's because isomorphic-fetch does not do export deafult so you have to pull in the imports by name, or use the notation I wrote above. Take a look at the MDN link I put on top.

like image 149
javinor Avatar answered Nov 29 '25 13:11

javinor