babel-plugin-module-resolver
babel-plugin-module-resolver copied to clipboard
"Module not found" when using named re-exporting from an aliased path
"Module not found" will occur when all of the following conditions are met:
- Using a named re-export, such as
export { a } from ...
- Re-exporting from an aliased path, such as
... from 'Root/mod'
- ES module is enabled, i.e.
["es2015", {"modules": false}]
See the following minimal sample: https://gist.github.com/dkwingsmt/37cfca39948da637d29b90c8448155f9
Versions
- node: v6.11.2
- npm: 3.10.10
- OS: macOS 10.12.6 (16G29)
I am having the same problem but only when trying to import a component that exists on the same level.
export Flex from './Flex'
export Box from './Box'
In the Flex.js
file, if I do
import { Box } from 'components/atoms'
it returns undefined.
@fatfisz any idea? Would definitely like to fix it before the next release.
I'll add that on my todo to check the given example and try to find out the root cause of it if you're busy in the next few days :)
It looks like a problem with circular dependencies IMO... not relevant to the plugin.
We have a test with export { something } from "${source}"
, so this definitely works (it also works in Codility codebase, where we are using all known forms of export/import 😄).
@protoEvangelion try import Box from 'components/atoms/Box'
or swap Flex with Box in components/atoms/index.js
and see if that works. From what I see, first index.js
is imported, which then imports from Flex.js
, which in turn goes back to the unfinished index.js
to get Box
, which at that point in time is undefined
.
Important note
Since I suspect this issue has nothing to do with the plugin, I'd like to ask for minimal reproduction repos/gists. Given all described patterns are tested and are confirmed to work, the problems most probably come from other place.
this also happened in my project. when i just run babel with babel-cli, i got this
// original
import importedModule from '@src/module';
export { default as reExportedModule } from '@src/module';
// transpiled
import importedModule from './src/module';
export { default as reExportedModule } from '@src/module';
^^^^^^^^^^^
Oh my. export { default as something } from
was not supported by babel!