[Vuejs]-Why does the ES6 module import expression not work for json files in assets folder with some path arguments?

0👍

You need to be aware of the fact that import() statements in today’s common JS project (including Vue) are processed by Webpack at build time, not just at runtime

At build time Webpack needs to know which file is imported so it can make it available for consumption at runtime (transpile JS, pre-process SCSS etc). But because this import is dynamic and Webpack cannot execute your code, it can not possibly know what the argument passed into import() exactly means. It can only parse the code and make a guess – "Which file can be imported here?" (based on the content of your file system)

So it makes no sense to look at the examples and compare the cases from "JavaScript execution" point of view because what works and what does not ultimately depends on Webpack’s ability to parse the expression inside () and make a correct guess…

More on this in Webpack’s docs – Dynamic expressions in import()

Leave a comment