Tilde path does not work when importing css from node_modules
.sassrc
{
"includePaths": ["node_modules"]
}
package.json
"devDependencies": {
"parcel-bundler": "^1.12.3",
"sass": "^1.17.3"
},
"dependencies": {
"react-simplemde-editor": "^4.0.0"
}
cli command
parcel serve index.html
main.scss
@import '~/easymde/dist/easymde.min.css';
index.js
import './main.scss';
Parcel should bundle everything without errors
I get the next error:
/Users/xmikasax/git/parcel_css_import_mwe/main.scss:1:1: Cannot resolve dependency '~/easymde/dist/easymde.min.css' at '/Users/xmikasax/git/parcel_css_import_mwe/~/easymde/dist/easymde.min.css'
The reason might be in package name (it is 'react-simplemde-editor') while its folder with styles in node_modules is 'easymde'
https://github.com/xmikasax/parcel_css_import_mwe
| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 1.12.3 |
| Node | 11.12.0 |
| npm/Yarn | 6.9.0 |
| Operating System | Mac OS |
Parcel resolves ~ to the nearest folder containing node_modules, so you usually need to do something like this: ~/node_modules/easymde/dist/easymde.min.css
Does this work for your?
Docs: https://parceljs.org/module_resolution.html#~-tilde-paths
Yes, it works, thank you. But what does package root: the directory of the nearest module root in node_modules in docs stand for?
Basically the same as nearest package root:
The algorithm goes up one level in the file hierarchy and stops when the next level up would be node_modules or the root of your project was reached.
pkg-1
|- src
|- index.js (`~` resolves to `pkg-1` because of project root )
|- node_modules
|- some-dep
|- index.js (`~` resolves to `some-dep` because of node_modules)
Thank you.