Lets say I'd like to import some stylesheets from a node module in my main app.scss
:
@import '~bootstrap/scss/bootstrap';
This will be correctly resolved by PhpStorm, and built by Nuxt.js as well, all good.
Now if I want to do the same for a scoped node module (a node module with a name in the format of @scope/module
) Nuxt.js and PhpStorm diverges:
@import '@fortawesome/fontawesome-svg-core/styles.css';
This works fine in Nuxt.js, build goes on without issues, but PhpStorm underlines the whole thing saying
Cannot resolve directory '@fortawesome'
@import '~@fortawesome/fontawesome-svg-core/styles.css';
This is understood by PhpStorm and can be resolved just fine, however causes Nuxt.js build to fail with:
ERROR in ./client/assets/sass/app.scss
Module build failed (from ./node_modules/extract-css-chunks-webpack-plugin/dist/loader.js):
ModuleBuildError: Module build failed (from ./node_modules/postcss-loader/src/index.js):
Error: Can't resolve '~@fortawesome/fontawesome-svg-core/styles.css'
So my question is: Which syntax would be considered correct, and is it possible to make both PhpStorm and Nuxt.js happy at the same time?
For me the ~@
seems to make more sense, as ~
resolves to the path of my node_modules
and the actual folder name in there starts with a @
. Using only @
kind of breaks the pattern compared to non-scoped node modules, for which ~
prefix is needed according to both PhpStorm and Nuxt.js.