Parcel: Can't use tilde paths to import css from node_modules

Created on 27 Mar 2019  路  4Comments  路  Source: parcel-bundler/parcel

馃悰 bug report

Tilde path does not work when importing css from node_modules

馃帥 Configuration (.babelrc, package.json, cli command)

.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';

馃 Expected Behavior

Parcel should bundle everything without errors

馃槸 Current Behavior

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'

馃拋 Possible Solution

The reason might be in package name (it is 'react-simplemde-editor') while its folder with styles in node_modules is 'easymde'

馃敠 Context

馃捇 Code Sample

https://github.com/xmikasax/parcel_css_import_mwe

馃實 Your Environment

| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 1.12.3 |
| Node | 11.12.0 |
| npm/Yarn | 6.9.0 |
| Operating System | Mac OS |

Question

All 4 comments

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)

https://github.com/parcel-bundler/parcel/blob/636bb50baeae15730c3b91cd3b58b457c31f7200/packages/core/parcel-bundler/src/Resolver.js#L128-L144

Thank you.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

davidnagli picture davidnagli  路  3Comments

Niggler picture Niggler  路  3Comments

algebraic-brain picture algebraic-brain  路  3Comments

donaldallen picture donaldallen  路  3Comments

dsky1990 picture dsky1990  路  3Comments