I have index.js with:
import a from './lib/a'
And inside folder lib I have two file a.js and b.js, now in a.js I do:
import b from '/b'
// I also try both:
import b from './lib/b'
// And
import b from 'b'
But run node -r esm index.js false with error:
Error: Cannot find module 'b'
How can I import b.js from a.js and import a.js from index.js and run index.js with esm?
seems like you forgot the leading dot in './b' otherwise the module loader tries to load from the top level of the project.
// lib/a.js
import b from './b'
Hi @stpham-net!
import b from 'b' is a bare import and will try to resolve 'b' as a npm package.import b from '/b' will try to resolve b.js from the root of your system _(assuming *nix based)_As @dnalborczyk points out import b from './b' is a relative import and should work for you.
Thanks to @dnalborczyk and @jdalton!