Skip to content

Commit

Permalink
Fix warning message bug (#512)
Browse files Browse the repository at this point in the history
* Fix warning message bug

* Add troubleshooting section on ENOENT errors
  • Loading branch information
drwpow authored Jun 18, 2020
1 parent 84211d7 commit ab78391
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
30 changes: 30 additions & 0 deletions docs/docs/09-troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,34 @@ module.exports = {
};
```

### No such file or directory

If you encounter a warning message such as this:

```
ENOENT: no such file or directory, open …/node_modules/csstype/index.js
```

That may be due to the fact that there was nothing Snowpack could bundle. In the case of `csstype`, it only emits a TypeScript definition (`.d.ts`) file, so Snowpack can’t bundle it!

There are 2 ways to solve this:

##### Option 1: importing `type`

```ts
import type { something } from 'csstype';
```

Using the `import type` keyword is friendlier in most cases. Sometimes Snowpack can correctly determine when you’re importing TypeScript types, but sometimes it has trouble—mostly it depends on how each package is configured (and no 2 packages are alike!). Using `import type` helps.

##### Option 2: manual `install`

If Snowpack still is having trouble with certain packages, you can manually set `install` in `snowpack.config.js` like so:

```json
{
"install": ["package-one", "package-two", "package-three"]
}
```

This isn’t ideal because now you have to maintain this list, and omit the packages that are giving you trouble. However, sometimes this is the quickest way to fix the issue.
8 changes: 6 additions & 2 deletions src/commands/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,12 @@ export async function install(
warning.plugin === 'snowpack:rollup-plugin-catch-unresolved'
) {
// Display posix-style on all environments, mainly to help with CI :)
const fileName = warning.id!.replace(cwd + path.sep, '').replace(/\\/g, '/');
logError(`${fileName}\n ${warning.message}`);
if (warning.id) {
const fileName = warning.id.replace(cwd + path.sep, '').replace(/\\/g, '/');
logError(`${fileName}\n ${warning.message}`);
} else {
logError(`${warning.message}. See https://www.snowpack.dev/#troubleshooting`);
}
return;
}
warn(warning);
Expand Down

1 comment on commit ab78391

@vercel
Copy link

@vercel vercel bot commented on ab78391 Jun 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.