[v5] cannot do truly dynamic import: Property value expected type of string but got null
See original GitHub issueDescribe the bug
This works:
componentDidMount = () => {
import('../Test.mdx').then(Thing =>
this.setState({ Thing: Thing.default })
);
};
but this doesnt work
componentDidMount = () => {
const path = '../Test.mdx';
import(path).then(Thing =>
this.setState({ Thing: Thing.default })
);
};
It generates this opaque compile error:
Failed to build! Fix any errors and try again!
./src/containers/Home.js
Module build failed: TypeError: /Users/swyx/Work/react-static-mdx/src/containers/Home.js: Property value expected type of string but got null
I assume it has something to do with this babel plugin: https://github.com/airbnb/babel-plugin-dynamic-import-node/issues/15
Is this “truly dynamic” kind of import supported? or am I doing something wrong?
Desktop (please complete the following information):
- OS: ios
- Browser: chrome
- Version: v5.9.12
Additional context just trying to make dynamically importing components based on route data
Issue Analytics
- State:
- Created 5 years ago
- Comments:6
Top Results From Across the Web
Property value expected type of string but got null; Dynamic ...
I am having issues using dynamic imports with variables in the path name. Trying to load dynamically the language.
Read more >Property value expected type of string but got null
The issue was do to the ES6 syntax, that works fine: export default function Icon({ type }) { return ( <div> <img src={iconSrc[type]} ......
Read more >Module Methods - webpack
A normal import statement cannot be used dynamically within other logic or contain variables. See the spec for more information and import() below...
Read more >getter - JavaScript - MDN Web Docs - Mozilla
The get syntax binds an object property to a function that will be called when that property is looked up. It can also...
Read more >Errors | Node.js v19.3.0 Documentation
code property is a string label that identifies the kind of error. error.code is the most stable way to identify an error. It...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Alrighty! Good luck! I know context switching can get to us when the quantity starts increasing.
Here if you need me!
@sw-yx if this helps, this seems to work.
or more similar to your example