FredKSchott/snowpack

[BUG] Creating an empty `snowpack.config.js` causes other snowpack commands to expect a missing module

Open

#3441 opened on Jun 10, 2021

View on GitHub
 (6 comments) (2 reactions) (0 assignees)JavaScript (19,541 stars) (923 forks)batch import
bugcontributors welcome!good first issue

Description

Bug Report Quick Checklist

  • 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 10.13.6
  • I run Snowpack on Node.js v14.7.0

Describe the bug

snowpack dev works perfectly for me locally. with no snowpack.config.js. I have installed @snowpack/plugin-webpack ^2.3.1 and am now trying to build/bundle my project.

  • Whenever I create an empty snowpack.config.js (invoked via snowpack init), snowpack dev breaks with a ReferenceError to a missing module it expects.
  • snowpack build also breaks in the same way.
  • If I delete snowpack.config.js and change nothing else, snowpack dev works perfectly again.
  • snowpack build also works without a snowpack.config.js, the downside being that I can't configure the build.

The same error trace is invariant to re-evaluating my shell, restarting terminal, restarting my computer, or nuking my node modules and trying again.

> snowpack dev

(node:20522) UnhandledPromiseRejectionWarning: ReferenceError: module is not defined
    at file:///<my_repo_dir>/snowpack.config.js:5:1
    at ModuleJob.run (internal/modules/esm/module_job.js:152:23)
    at async Loader.import (internal/modules/esm/loader.js:177:24)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:20522) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:20522) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

To Reproduce

Set up node env with npm init --yes in my project folder, set up project dependencies.

The only non-snowpack dependency in my project is p5 ^1.3.1. I have tried to make snowpack work both with my code set up to expect P5 as an old-school import (<script src="..."></script> to a local file) or with ES6 imports (import p5 from 'p5';), and it doesn't seem to make a difference either way.

I followed the setup instructions at Snowpack.dev Quick Start.

  1. npm install --save-dev snowpack
  2. Aliased the snowpack runner commands:
// within package.json
"scripts": {
    "start": "snowpack dev",
    "init": "snowpack init",
    "build": "snowpack build"
}
  1. Check that dev server works. npm run start

I then followed the setup instructions at Snowpack.dev Build Pipeline.

  1. npm install --save-dev @snowpack/plugin-webpack
  2. Added plugin information to package.json.
// within package.json
{
  "plugins": [["@snowpack/plugin-webpack"]]
}
  1. Check that npm run start and npm run build work.
  2. npm run init to create a snowpack config file.
  3. Received the error shown in the previous section.

Expected behavior

I expected snowpack to continue working as before upon creation of an empty config file.

Contributor guide