I'm attempting to bring in a static .json
file within the <script>
section of a .Vue
file using the code snippet
import Test from '@assets/test.json'
From what I've gathered about webpack, this should work effortlessly. I have even gone as far as explicitly specifying both the .json
extension in webpack resolve and including the json loader under loaders.
Despite my efforts, it continues to fail with the following error:
ERROR Failed to compile with 1 errors 9:14:24 AM
This dependency was not found:
* @assets/test.json in ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/Settings.vue?vue&type=script&lang=js&
To install it, you can run: npm install --save @assets/test.json
This seems peculiar since it's not a dependency that is meant to be installed?
The content of my test.json
file simply contains {}
, but I've also attempted it with an actual data file resulting in the same error message.
Thank you in advance for any assistance.
Edit: A big thank you to @tao for assisting me in resolving the issue through chat. The mistake was indeed straightforward:
import Test from '@assets/test.json'
should have been import Test from '@/assets/test.json'