question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Snowpack builds before scripts run

See original GitHub issue

Bug Report Quick Checklist

  • I am on the latest version of Snowpack & all plugins.
  • I use package manager npm
  • I run Snowpack on OS Linux
  • I run Snowpack on Node.js v12+

Describe the bug

On snowpack 3.3.6 (latest), scripts specified through @snowpack/plugin-run-script run after snowpack builds.

So I see errors like: [snowpack] config.mount[~/Desktop/11st-starter-kit/src/_site]: mounted directory does not exist.

This seems to introduced in 3.0.13 (See https://github.com/stefanfrede/11st-starter-kit/issues/156). Although same error message exists on 3.0.12, build seems to work as intended (scripts build before snowpack).

To Reproduce

git clone https://github.com/stefanfrede/11st-starter-kit.git
cd 11st-starter-kit
git checkout fa11f234e5beb705eaed1752a3047c24a2d8221f
npm install
npm install snowpack@latest
npx snowpack --version
npx snowpack build

See how snowpack builds before eleventy does:

[18:23:24] [snowpack] 3.3.6
[18:23:26] [snowpack] config.mount[~/Desktop/11st-starter-kit/src/_site]: mounted directory does not exist.
-------------------------------------------------------------------------------------------------------------
[18:23:26] [snowpack] ! building files...
-------------------------------------------------------------------------------------------------------------
[18:23:27] [eleventy] Writing src/_site/404.html from ./src/404.md.
[18:23:27] [eleventy] Writing src/_site/about/index.html from ./src/about.md.
[18:23:27] [eleventy] Writing src/_site/index.html from ./src/index.md.
[18:23:27] [eleventy] Copied 16 files / Wrote 3 files in 0.33 seconds (v0.12.1)
[18:23:27] [eleventy] Command completed.
-------------------------------------------------------------------------------------------------------------
[18:23:28] [snowpack] import alpinejs@latest → https://pkg.snowpack.dev/alpinejs
[18:23:28] [snowpack] pin dependency to this version: `snowpack add alpinejs`
[18:23:29] [snowpack] ✔ files built. [2.94s]
[18:23:29] [snowpack] ! building dependencies...
[18:23:29] [snowpack] ✔ dependencies built. [0.00s]
[18:23:29] [snowpack] ! writing to disk...
[18:23:29] [snowpack] ✔ write complete. [0.03s]
[18:23:29] [snowpack] ! optimizing build...
.......

Relevent snowpack config:

  plugins: [
    [
      '@snowpack/plugin-run-script',
      {
        cmd: 'eleventy',
        watch: '$1 --watch',
      },
    ],
  ],

Expected behavior

Scripts build before snowpack does. Here (3.0.12) builds fine, although with same error message.

❯ npx snowpack --version
[snowpack] 3.0.12
❯ npx snowpack build
[snowpack] config.mount[~/Desktop/11st-starter-kit/src/_site]: mounted directory does not exist.
[eleventy] Writing src/_site/404.html from ./src/404.md.
[eleventy] Writing src/_site/about/index.html from ./src/about.md.
[eleventy] Writing src/_site/index.html from ./src/index.md.
[eleventy] Copied 16 files / Wrote 3 files in 0.23 seconds (v0.12.1)
[snowpack] ! building source files...
[snowpack] ✔ build complete [1.21s]
[snowpack] ! building dependencies...
[snowpack] ✔ dependencies ready! [1.17s]
[snowpack] ! verifying build...
[snowpack] ✔ verification complete [0.00s]
[snowpack] ! writing build to disk...
[snowpack] ! optimizing build...
[snowpack] ✔ optimize complete [0.15s]
[snowpack] ▶ Build Complete!

Related

#2936

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:5
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
andreasphilcommented, Jul 4, 2021

This is probably the same bug I have observed here: https://github.com/snowpackjs/snowpack/issues/3095

I started working on a fix for snowpack build back then: https://github.com/andreasphil/snowpack/tree/build-step-plugin-order

I made snowpack await plugins during builds and delayed mounting until the plugins finished, so all plugin output is included and up to date. That solves the issue for me, but it breaks a couple of tests and I don’t know when I’ll get around to fixing them - life has been busy lately 😶 (if anyone else has the time feel free to take it from here).

Regarding snowpack dev, that still only works if at least some eleventy output already exists when the dev server boots. Apparently the eleventy plugin starts after the initial mounting but finishes before file watching begins. Somehow that causes snowpack to not notice the output files at all, even if they change again, until I restart the server. After that it works fine though, so it’s not a huge problem in development except when serving a repository for the first time after cloning or rming the eleventy output. In the interest of keeping the dev server startup fast I don’t think we want to await all plugins like in snowpack build. So I’m not sure what a good solution would be here, but probably the plugin output should get picked up by the file system watcher just like it does with regular JS files.

@colelawrence Someone in the other ticket noted that everything worked as expected until v3.0.13 - you could give that a try if you need something more recent than 2?

2reactions
gremocommented, May 26, 2021

I have the exact same problem. Latest working version is 3.0.13. My Eleventy _out directory is full of HTML files, the plugin run… but HTML files are missing from Snowpack _dist folder.

It’s so sad that something has changed. This official documentation MUST be updated because it’s not valid anymore.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[BUG] Snowpack builds before scripts run · Issue #3289 - GitHub
On snowpack 3.3.6 (latest), scripts specified through @snowpack/plugin-run-script run after snowpack builds. So I see errors like: [snowpack] ...
Read more >
[BUG] Creating an empty `snowpack.config.js` causes other ... - Rysolv
I am on the latest version of Snowpack (3.5.6) & all plugins. I use package manager npm v6.14.13; I run Snowpack on OSX...
Read more >
How Snowpack Works
Snowpack serves your application unbundled during development. Each file is built only once and is cached until it changes.
Read more >
@snowpack/plugin-run-script - npm
Run any CLI command as a part of Snowpack's dev server and production build. Useful for languages not supported by Snowpack plugins. This ......
Read more >
Getting Started with Svelte - Snowpack
Restart your Snowpack dev server to run it with the new configuration. Exit the process (ctrl + c in most Windows/Linux and cmd...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found