Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parcel does not resolve asset by absolute path #3929

Closed
anivle opened this issue Dec 18, 2019 · 4 comments
Closed

Parcel does not resolve asset by absolute path #3929

anivle opened this issue Dec 18, 2019 · 4 comments

Comments

@anivle
Copy link

anivle commented Dec 18, 2019

🐛 bug report

Parcel does not resolve absolute path CSS modules.
Issue looks exact as this

🎛 Configuration (.babelrc, package.json, cli command)

package.json:

{
  "name": "parcel-import-issue-reproduce",
  "version": "1.0.0",
  "description": "blablab",
  "main": "index.js",
  "scripts": {
    "dev": "parcel ./src/index.html",
    "build": "parcel build ./src/index.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "autoprefixer": "^9.7.3",
    "parcel-bundler": "^1.12.4",
    "parcel-plugin-css-regex-replace": "^0.1.1",
    "postcss-modules": "^1.4.1"
  },
  "dependencies": {
    "react": "^16.12.0",
    "react-dom": "^16.12.0"
  },
  "config": {
    "theme": "default"
  }
}

🤔 Expected Behavior

Parcel resolves path successfully.

😯 Current Behavior

Parcel fails to build with error:

 > parcel build ./src/index.js

🚨  /Users/aleonov/dev/parcel-import-issue-reproduce/src/Title.css:1:1: Cannot resolve dependency '/Users/aleonov/dev/parcel-import-issue-reproduce/src/themes/default/theme.css' at '/Users/aleonov/dev/parcel-import-issue-reproduce/src/themes/default/theme.css'
> 1 | @import '/Users/aleonov/dev/parcel-import-issue-reproduce/src/themes/default/theme.css';
    | ^
  2 |
  3 | .title {
# ls -la /Users/aleonov/dev/parcel-import-issue-reproduce/src/themes/default/
total 16
drwxr-xr-x  4 aleonov  staff  128 Dec 18 15:47 .
drwxr-xr-x  3 aleonov  staff   96 Dec 18 15:47 ..
-rw-r--r--  1 aleonov  staff   60 Dec 18 15:47 colors.css
-rw-r--r--  1 aleonov  staff  113 Dec 18 15:47 theme.css

💁 Possible Solution

🔦 Context

Trying to implement themes using parcel and parcel-plugin-css-regex-replace plugin.

I'm placing placeholder in css file like:
@import 'theme_import_placeholder';
and replacing it with absolute path of the file that contains theme colours set up on build time with parcel-plugin-css-regex-replace plugin:
@import '/Users/aleonov/dev/parcel-import-issue-reproduce/src/themes/default/theme.css';

💻 Code Sample

repo: https://github.com/anivle/parcel-import-issue-reproduce

🌍 Your Environment

Software Version(s)
Parcel ^1.12.4
Node v8.16.2
npm/Yarn npm 6.4.1
Operating System MacOS 10.14.6 (18G95)
@DeMoorJasper
Copy link
Member

Yeah, this will probably never be supported. (although in parcel 2 there will be the possibility to write a custom resolver to support this)

Supporting absolute paths that are not relative to the project are a bad idea as it might leak your file structure to the bundles which might be a security risk.

The more important reason this is a bad idea is because it would break if the file structure changes, and a project should only rely on files inside the project folder not random files all across your computer.

@anivle
Copy link
Author

anivle commented Dec 19, 2019

@DeMoorJasper Thanks a lot for your reply. I just saw #1986 that was fixed and thought it was kind of regression.
Regarding structure change. It's just replaced at build time. So if the file structure changes this would be changed too.

@DeMoorJasper
Copy link
Member

@anivle you could also generate relative paths on build time?

@anivle
Copy link
Author

anivle commented Dec 19, 2019

@DeMoorJasper Check on this. Thanks much for your reply.

@anivle anivle closed this as completed Dec 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants