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

Strip ~ from import/use/forward statements #114

Closed
shellscape opened this issue Dec 28, 2022 · 3 comments · Fixed by #115
Closed

Strip ~ from import/use/forward statements #114

shellscape opened this issue Dec 28, 2022 · 3 comments · Fixed by #115

Comments

@shellscape
Copy link
Contributor

Hey there. Thanks for this plugin.

It's unfortunately common for folks to use a tilde ~ in import statements, which this plugin doesn't yet support. That ends up throwing a build error. Packages like https://www.npmjs.com/package/@ircc-ca/ds-sdc-core use this, and it's so common that webpack's loader accounts for this.

sass/dart-sass#801 covers this as well, and the recommendation is to remove the ~.

Any chance this could be supported?

@glromeo
Copy link
Owner

glromeo commented Dec 29, 2022

~ imports are supported out of the box as you can see here:


what is not immediate but still supported is to have css imports using tilde as seen here:
#74
but also this might help:
#39

if that still doesn't work feel free to reopen this issue provided an example repo where the ~ import is an issue

@glromeo glromeo closed this as completed Dec 29, 2022
@shellscape
Copy link
Contributor Author

I'll put together a repl.it for the failing case I ran into.

@shellscape
Copy link
Contributor Author

shellscape commented Dec 29, 2022

@glromeo I believe this has to do with the esbuild absWorkingDir setting. This REPL https://replit.com/@shellscape/failing-tilde-esbuild demonstrates the problem.

The build target is in the target directory (which repl.it unfortunately puts under the Packager Files section).

To run, enter the following commands in the Shell terminal window - don't click the Run button!

yarn
node index.mjs

The build config is in the build.mjs file. We're telling esbuild that the target is in a separate directory than the execution directory (hence a difference cwd). It appears that esbuild-sass-plugin isn't taking that into account and is looking at the cwd/root node_modules and throwing an error. If you add @ircc-ca/ds-sdc-core to the project root node_modules, the plugin is able to function correctly.

Edit

Looking at the source, it appears that

export function modulesPaths(): string[] {
let path = process.cwd()
let {root} = parse(path)
let found: string[] = []
while (path !== root) {
const filename = resolve(path, 'node_modules')
if (existsSync(filename)) {
found.push(filename)
}
path = resolve(path, '..')
}
return [...found]
}
doesn't take into account build.options.absWorkingDir and that is likely the root cause. Other plugins have been bitten by the same bug e.g. https://github.com/egoist/esbuild-plugin-vue/pull/5/files

shellscape added a commit to shellscape/esbuild-sass-plugin that referenced this issue Dec 29, 2022
glromeo added a commit that referenced this issue Dec 29, 2022
fix: use absWorkingDir as root if provided. fixes #114
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants