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

Does not work on Windows #3

Open
TheLonelyAdventurer opened this issue Jul 7, 2021 · 0 comments
Open

Does not work on Windows #3

TheLonelyAdventurer opened this issue Jul 7, 2021 · 0 comments

Comments

@TheLonelyAdventurer
Copy link

This plugin fails on Windows because of backslashes in paths.

This is my case:

esbuild.build({
  entryPoints: [ './src/index.js' ],
  bundle: true,
  outfile: './dist/bundle.js',
  plugins:
    [ esbuild_sass()
    , esbuild_css_modules(
    { localIdentName: "[local]--[hash:8:md5:hex]"
    , extension: '.module.css'
    }
    )
    ],
  minify: !isDev(),
  minifyIdentifiers: !isDev(),
  minifySyntax: !isDev(),
  minifyWhitespace: !isDev(),
  sourcemap: isDev() ? 'external' : false,
  platform: 'browser'
})

Which currently produces this result:

Error: Build failed with 1 error:
../../../AppData/Local/Temp/tmp-5848-66jQXSM4BQce/nuts/src/index.module.css:2:15: error: Could not resolve "C:Users\rmancAppDataAppDataLocalTemp\tmp-5848-66jQXSM4BQce\nutssrcindex.css" (mark it as external to exclude it from the bundle)
    at failureErrorWithLog (C:\Users\rmanc\Documents\projs\nuts\node_modules\esbuild\lib\main.js:1449:15)
    at C:\Users\rmanc\Documents\projs\nuts\node_modules\esbuild\lib\main.js:1131:28
    at runOnEndCallbacks (C:\Users\rmanc\Documents\projs\nuts\node_modules\esbuild\lib\main.js:921:63)
    at buildResponseToResult (C:\Users\rmanc\Documents\projs\nuts\node_modules\esbuild\lib\main.js:1129:7)
    at C:\Users\rmanc\Documents\projs\nuts\node_modules\esbuild\lib\main.js:1236:14
    at handleIncomingPacket (C:\Users\rmanc\Documents\projs\nuts\node_modules\esbuild\lib\main.js:706:9)
    at Socket.readFromStdout (C:\Users\rmanc\Documents\projs\nuts\node_modules\esbuild\lib\main.js:576:7)
    at Socket.emit (events.js:376:20)
    at addChunk (internal/streams/readable.js:309:12)
error Command failed with exit code 1.

I noticed the path C:Users\rmancAppDataAppDataLocalTemp\tmp-5848-66jQXSM4BQce\nutssrcindex.css and looked at the source:

let contents = `
import "${tmpFilePath}";
const result = ${JSON.stringify(classMap)};
export default result;
`;

The generated code looks like this:

import "C:\Users\rmanc\AppData\AppData\Local\Temp\tmp-5848-66jQXSM4BQce\nuts\src\index.css";
const result = {"test":"test--h0aba64c6"};
export default result;

which obviously doesn't work.

--

I've managed to make it work by wrapping tmpFilePath with https://github.com/sindresorhus/slash.

I'm writing a PR addressing this issue.

TheLonelyAdventurer added a commit to TheLonelyAdventurer/esbuild-plugin-css-modules that referenced this issue Jul 7, 2021
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

No branches or pull requests

1 participant