-
Notifications
You must be signed in to change notification settings - Fork 40
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
Pure esbuild sass files with relative assets fails to load #48
Comments
I never saw an error message like that, can you help me reproduce this issue? If you could share the repo that would be great! |
Yes I just obfuscated the complete path to ..... I should have put * Edit: Reproduction https://github.com/Hideman85/esbuild-sass-test-case
|
This actually is a similar issue to #19 indeed... {
name: "resolve-assets",
setup(build) {
build.onResolve({filter: /./}, ({path, resolveDir, importer, namespace})=>{
console.log("resolve:", path, resolveDir, importer, namespace)
return null;
})
}
} the issue is not in the plugin but in esbuild trying and resolving the font url from the source file and not the sass file
I can't take plugins: [
sassPlugin({
outputStyle: isProd ? 'compressed' : 'expanded'
}),{
name: "resolve-assets",
setup(build) {
build.onResolve({filter: /.ttf$/}, (args)=>{
try {
return {path: require.resolve(args.path, {paths: ['./fonts']})}
} catch (e) {
console.error(e)
return null;
}
})
}
}
] of course this solution is pretty poor but it might be the starting point for something that works for your project layout. NOTE: The issue is that the importer of the asset (.ttf) is an information that sass has swallowed and neither the plugin or esbuild can have |
Thanks for your complete answer, then I'm gonna open an issue in esbuild I don't like the resolve assets hand made fix it does not fit at scale. |
sorry @Hideman85 but esbuild author can't help you there!
|
But then this is not usable, we cannot tell all the users:
|
The issue is within SASS and a solution might come from sass/sass#2535 |
Yes currently I'm with webpack + babel + terser and that is horribly slow that's why I was looking to move to esbuild. |
Node sass has the same issue but at least it would allow importers to intercept all @imports and one could hack into that to This is the only hope: sass/sass#2535 by the way parcel and rollup have the same issues and what resolve-url-loader does is just crazy! |
Wow the resolve-url-loader is indeed crazy 😂 Our only hope rely on a issue opened more than 3 years ago 😢 I would say that it would probably happen a day but that does not look like for the near feature. Maybe we can upvote the issue by adding our case and maybe it would boost it |
Hi @Hideman85 I just published https://www.npmjs.com/package/esbuild-sass-plugin/v/2.0.0-alpha.0 in npm. Just switch to 2.0.0-alpha.0 and in you example configure the plugin like this: plugins: [
sassPlugin({
outputStyle: isProd ? 'compressed' : 'expanded',
// transform: postcssModules({
// // ...put here the options for postcss-modules: https://github.com/madyankin/postcss-modules
// })
precompile(source, pathname) {
console.log("precompile:", pathname)
return source.replace(/(url\(['"])(\.\.?\/)([^'"]+['"]\))/g, `$1${path.dirname(pathname)}/$2$3`)
}
})
] I look forward to hear if it works in your codebase! |
Hi @glromeo thanks for the update and your work 🙂 ✘ [ERROR] ENOENT: no such file or directory, open 'tmp/project/src/_variables.scss'
╷
1 │ @import "../../../variables";
│ ^^^^^^^^^^^^^^^^^^^^
╵
- 1:9 root stylesheet
src/components/SharedComponents/CardSelector.tsx:6:7:
6 │ import './styles/CardSelectorStyles.scss' I note that the logging do not contains a beginning |
hmm... the |
I just ran my test case with dependencies up to date like: "devDependencies": {
"esbuild": "~0.14.6",
"esbuild-sass-plugin": "~2.0.0-alpha.0"
}, And got this without the need of extra files: └─$ yarn node build.js 1 ⚙
precompile: /tmp/esbuild-sass-test-case/src/style.scss
✘ [ERROR] [plugin sass-plugin] ENOENT: no such file or directory, open 'tmp/esbuild-sass-test-case/fonts/fonts.scss'
╷
1 │ @import '../fonts/fonts.scss';
│ ^^^^^^^^^^^^^^^^^^^^^
╵
- 1:9 root stylesheet
src/index.js:1:7:
1 │ import './style.scss'
╵ ~~~~~~~~~~~~~~
(node:233087) UnhandledPromiseRejectionWarning: Error: Build failed with 1 error:
src/index.js:1:7: ERROR: [plugin: sass-plugin] ENOENT: no such file or directory, open 'tmp/esbuild-sass-test-case/fonts/fonts.scss'
╷
1 │ @import '../fonts/fonts.scss';
│ ^^^^^^^^^^^^^^^^^^^^^
╵
- 1:9 root stylesheet
at failureErrorWithLog (/tmp/esbuild-sass-test-case/node_modules/esbuild/lib/main.js:1503:15) I seen this: yarn why esbuild
├─ esbuild-sass-plugin@npm:2.0.0-alpha.0
│ └─ esbuild@npm:0.14.6 (via npm:^0.14.5)
│
└─ test-case@workspace:.
└─ esbuild@npm:0.14.6 (via npm:~0.14.6) Same output after downgrade, have you tired out? I'm on latest Ubuntu 21.10. EDIT: The error is same without the precompile, does it mean the precompile is not doing the intended action? EDIT2: Whatever I do it does not work 🤔 but putting back to |
looks an issue with the path separators...I am going to try it on my mac. Thanks for the help troubleshooting! |
please update to https://www.npmjs.com/package/esbuild-sass-plugin/v/2.0.0-alpha.1 ! |
It does solve the issue but now it remains two points:
EDIT: Test case updated yarn node build.js
precompile: /tmp/esbuild-sass-test-case/src/style.scss
precompile: /tmp/esbuild-sass-test-case/fonts/fonts.scss
✘ [ERROR] [plugin sass-plugin] Stack Overflow
╷
4 │ @import '../lib/SomeLib/builtIn'; // Note the extension should not be added, this is intended to use namespace feature
│ ^^^^^^^^^^^^^^^^^^^^^^^^
╵
- 4:11 root stylesheet
src/index.js:1:7:
1 │ import './style.scss'
╵ ~~~~~~~~~~~~~~ |
@Hideman85 I just released 2.0.0-alpha.3 |
@Hideman85 v2.0.0 has been published... I close this issue now |
Super thank you so much for your work, I will check out later :) |
I do have a relative import issue:
The file import a relative sass file
I found other issues on the repo like
@import "../../../fonts/fonts.scss";
and this file is importing the font.I do see other similar issues on the repo but I don't really get it... I try to find if this is due to dart-sass but no clue either....
Currently this is working with webpack but I do think like #19 this ise due to special resolver.
What can I do to solve my issue?
The text was updated successfully, but these errors were encountered: