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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 BUG: (Regression) Snowpack build fails when scanning node_modules/.bin/*.js file. #3712

Open
1 task done
NfNitLoop opened this issue Sep 13, 2021 · 4 comments
Open
1 task done

Comments

@NfNitLoop
Copy link

NfNitLoop commented Sep 13, 2021

Quick checklist

  • I am using the latest version of Snowpack and all plugins.

What package manager are you using?

npm

What operating system are you using?

Windows

Describe the bug

I just upgraded from Snowpack 3.0.11 to 3.8.8, and now snowpack build seems to be trying to parse a .js files inside of node_modules/.bin/. This is failing for a sha.js file which is actually a bash script wrapper for a package by that name, with the following contents:

#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")

case `uname` in
    *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;;
esac

if [ -x "$basedir/node" ]; then
  "$basedir/node"  "$basedir/../sha.js/bin.js" "$@"
  ret=$?
else 
  node  "$basedir/../sha.js/bin.js" "$@"
  ret=$?
fi
exit $ret

Unsurprisingly, Snowpack is unable to parse it as JS: snowpack build --verbose gives:

[...]
[17:55:00] [snowpack] BUILD: /node_modules/.bin/rimraf.ps1
[17:55:00] [snowpack] BUILD: /node_modules/.bin/rollup
[17:55:00] [snowpack] BUILD: /node_modules/.bin/rollup.cmd
[17:55:00] [snowpack] BUILD: /node_modules/.bin/rollup.ps1
[17:55:00] [snowpack] BUILD: /node_modules/.bin/semver
[17:55:00] [snowpack] BUILD: /node_modules/.bin/semver.cmd
[17:55:00] [snowpack] BUILD: /node_modules/.bin/semver.ps1
[17:55:00] [snowpack] BUILD: /node_modules/.bin/sha.js
[17:55:00] [snowpack] Scanning node_modules\.bin\sha.js for imports as JS
[17:55:00] [snowpack] Build Result Error: There was a problem with a file build result.
[17:55:00] [snowpack] Parse error @:5:28
[17:55:00] [snowpack] Error: Parse error @:5:28
    at parse (C:\Users\Cody\code\feoblog\web-client\node_modules\es-module-lexer\dist\lexer.cjs:1:402)
    at scanCodeImportsExports (C:\Users\Cody\code\feoblog\web-client\node_modules\snowpack\lib\cjs\rewrite-imports.js:21:29)
    at transformEsmImports (C:\Users\Cody\code\feoblog\web-client\node_modules\snowpack\lib\cjs\rewrite-imports.js:37:27)
    at Object.transformFileImports (C:\Users\Cody\code\feoblog\web-client\node_modules\snowpack\lib\cjs\rewrite-imports.js:108:16)
    at FileBuilder.resolveImports (C:\Users\Cody\code\feoblog\web-client\node_modules\snowpack\lib\cjs\build\file-builder.js:116:48)
    at async Object.loadUrl (C:\Users\Cody\code\feoblog\web-client\node_modules\snowpack\lib\cjs\commands\dev.js:641:39)
    at async flushFileQueue (C:\Users\Cody\code\feoblog\web-client\node_modules\snowpack\lib\cjs\build\process.js:191:24)
    at async Object.buildFiles (C:\Users\Cody\code\feoblog\web-client\node_modules\snowpack\lib\cjs\build\process.js:226:5)
    at async build (C:\Users\Cody\code\feoblog\web-client\node_modules\snowpack\lib\cjs\commands\build.js:11:5)
    at async Object.command (C:\Users\Cody\code\feoblog\web-client\node_modules\snowpack\lib\cjs\commands\build.js:35:9)

Steps to reproduce

Hmm, sorry, I'm not able to create a minimal reproduction. But my code is available to reproduce. Steps:

  1. git clone git@github.com:NfNitLoop/feoblog.git
  2. cd feoblog/web-client
  3. git checkout f94e9cdfa1e98d576b375dbc00c14420f15f10c9 (for reproducibility)
  4. npm install
  5. npm run build (runs snowpack build)

Succeeds. But if we upgrade:

  1. npm update snowpack
  2. npm run build (Or: npm run build -- --verbose)

... then I get the compile error.

Link to minimal reproducible example (optional)

https://github.com/NfNitLoop/feoblog/tree/f94e9cdfa1e98d576b375dbc00c14420f15f10c9

@NfNitLoop
Copy link
Author

Aha, a more "minimal" reproduction:

  1. npx create-snowpack-app --target bug-report --template @snowpack/app-template-blank
  2. cd bug-report
  3. npm install --save sha.js
  4. npm run build (Finishes OK)
  5. remove the mount section from snowpack.config.mjs
  6. npm run build -- --verbose

So, I guess the behavior of a config file when the mount section is missing was changed. But I can probably work around the issue by adding one.

@NfNitLoop
Copy link
Author

Related: Is there an easy way to view old versions of Snowpack docs? I'd love to figure out when mount was introduced/changed so I could read more about it.

@NfNitLoop
Copy link
Author

Hmm, no, this config

module.exports = {
    mount: {
        ".": "/"
    },
    exclude: [
        "package*.json",
        "snowpack.config.js",
        "svelte.config.js",
        "tsconfig.json",
        "**/.gitignore",
        "**/node_modules/**/*",

        "**/*.@(sqlite|sqlite3)",
    ],
// ...

Still tries to parse files inside of my node_modules/.bin directory. 馃

@NfNitLoop
Copy link
Author

It really looks like exclude is just being ignored in this case.

Even if I add these excludes:

        "sha.js",
        "**/sha.js",
        "node_modules\\.bin\\sha.js",
        "node_modules\.bin\sha.js",

(which snowpack build --verbose echoes out, so it's actually reading them)

... it still dies trying to parse sha.js.

I ended up working around the issue by just restructuring my files into a src/ subdirectory and specifying:

    mount: {
        "src": "/"
    },

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