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

Import node_modules not working when bundle is set to true #74

Closed
alex-w0 opened this issue Feb 24, 2022 · 9 comments
Closed

Import node_modules not working when bundle is set to true #74

alex-w0 opened this issue Feb 24, 2022 · 9 comments
Labels
enhancement New feature or request

Comments

@alex-w0
Copy link

alex-w0 commented Feb 24, 2022

When I'm trying to import a file from the node_modules with the symbol ~ then it will give me the following error. Writing the full path manually works.

@import '~dialog-polyfill/dist/dialog-polyfill.css';
esbuild.build({
  entryPoints: [
    '....'
  ],
  bundle: true,
  outdir: './css',
  plugins: [esbuildSass.sassPlugin()]
})
.catch(() => {
  process.exit(1)
})

✘ [ERROR] Could not resolve "~dialog-polyfill/dist/dialog-polyfill.css"

    src/sass/formio.form.scss:2:8:
      2 │ @import '~dialog-polyfill/dist/dialog-polyfill.css';
@glromeo
Copy link
Owner

glromeo commented Feb 24, 2022

your issue is likely a css import (i.e. not sass) being tried to be resolved by esbuild …I can’t just see that import in formio so if can’t tell more than that… I am happy to help you troubleshoot this but you have to come up with a github repo where you reproduce the issue

@glromeo glromeo added the question Further information is requested label Feb 24, 2022
@alex-w0
Copy link
Author

alex-w0 commented Feb 24, 2022

Yes true, it's a common css import which should recognize the tilde as an alias for the node_modules. The formio file just contains the import statement at the beginning. Here is the repo for reproducing the issue.

@glromeo
Copy link
Owner

glromeo commented Feb 25, 2022

the issue here is that sass doesn’t call the plugin importer because it’s a css so the import ends in the css that esbuild is trying to bundle and esbuild has no idea how to deal with ~ indeed if you remove ~ from your example url it builds just fine

@glromeo
Copy link
Owner

glromeo commented Feb 25, 2022

another option for you is to use the precompile in the plugin to change the url and remove the ~

@glromeo
Copy link
Owner

glromeo commented Feb 25, 2022

I’m on holidays with just an ipad when back I want to try and add another onResolve to the plugin to male life easier in these situations

the idea is the following

var esbuild = require('esbuild');
var esbuildSass = require('esbuild-sass-plugin');

esbuild
  .build({
    entryPoints: ['./src/formio.scss'],
    bundle: true,
    outdir: './css',
    plugins: [esbuildSass.sassPlugin(),
       {name:"temp",setup(build){
      build.onResolve({filter:/^~.*css$/},({path})=>{
        return {path: require.resolve(path.slice(1))}
      })
    }}],
    
  })
  .catch(() => {
    process.exit(1);
  });

@glromeo glromeo added enhancement New feature or request and removed question Further information is requested labels Feb 25, 2022
@alex-w0
Copy link
Author

alex-w0 commented Feb 25, 2022

I’m on holidays with just an ipad when back I want to try and add another onResolve to the plugin to male life easier in these situations

the idea is the following

var esbuild = require('esbuild');
var esbuildSass = require('esbuild-sass-plugin');

esbuild
  .build({
    entryPoints: ['./src/formio.scss'],
    bundle: true,
    outdir: './css',
    plugins: [esbuildSass.sassPlugin(),
       {name:"temp",setup(build){
      build.onResolve({filter:/^~.*css$/},({path})=>{
        return {path: require.resolve(path.slice(1))}
      })
    }}],
    
  })
  .catch(() => {
    process.exit(1);
  });

Yes no worry, writing the full path works fine for me, so this improvement is not really urgent or even tragic when it's not possible. Enjoy your holidays.

glromeo added a commit that referenced this issue Feb 26, 2022
@glromeo
Copy link
Owner

glromeo commented Feb 26, 2022

@alex-w0 you can upgrade to 2.2.4 and add cssImports: true to your options
thank you for your example repo!

@glromeo glromeo closed this as completed Feb 26, 2022
@alex-w0
Copy link
Author

alex-w0 commented Feb 28, 2022

Thanks works great 🚀 I also didn't know that the ~ is deprecated these days ^^

@tadman
Copy link

tadman commented Mar 2, 2022

For clarification, it's cssImports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants