FredKSchott / snowpack

ESM-powered frontend build tool. Instant, lightweight, unbundled development. ✌️
https://www.snowpack.dev
MIT License
19.48k stars 922 forks source link

πŸ› BUG: snowpack tries to import typescript files as js files, while using a workspace #3579

Open okikio opened 3 years ago

okikio commented 3 years ago

Quick checklist

What package manager are you using?

pnpm

What operating system are you using?

Linux

Describe the bug

While using Astro js (which builds on top of snowpack), I tried importing linked workspace packages whose main files are typescript files, when building Astro I got this error message,

pnpx astro build && pnpx astro dev
[config] Set "buildOptions.site" to generate correct canonical URLs and sitemap
[23:55:28] [snowpack] Ready!
[build] ! building pages...

warn - You have enabled the JIT engine which is currently in preview.
warn - Preview features are not covered by semver, may introduce breaking changes, and can change at any time.

warn - You have enabled the JIT engine which is currently in preview.
warn - Preview features are not covered by semver, may introduce breaking changes, and can change at any time.
[build] βœ” pages built.

[build] ! optimizing css...
warn - You have enabled the JIT engine which is currently in preview.
warn - Preview features are not covered by semver, may introduce breaking changes, and can change at any time.
[build] βœ” css optimized.
[build] ! copying public folder...
[build] βœ” public folder copied.
[build] ! bundling...
[23:55:32] [snowpack] path-to-regexp: Unscannable package import found.
Snowpack scans source files for package imports at startup, and on every change.
But, sometimes an import gets added during the build process, invisible to our file scanner.
We'll prepare this package for you now, but should add "path-to-regexp" to "knownEntrypoints"
in your config file so that this gets prepared with the rest of your imports during startup.
[23:55:32] [snowpack] path-to-regexp: Unscannable package import found.
Snowpack scans source files for package imports at startup, and on every change.
But, sometimes an import gets added during the build process, invisible to our file scanner.
We'll prepare this package for you now, but should add "path-to-regexp" to "knownEntrypoints"
in your config file so that this gets prepared with the rest of your imports during startup.
[23:55:32] [snowpack] Build Result Error: There was a problem with a file build result.
[build] [Error: Could not load /_snowpack/link/workspaces/native/packages/native/src/app.js (imported by ../../_snowpack/link/workspaces/native/packages/native/src/api.js): ENOENT: no such file or directory, open '/_snowpack/link/workspaces/native/packages/native/src/app.js'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/_snowpack/link/workspaces/native/packages/native/src/app.js',
  watchFiles: [
    '/_astro_frontend/hydrate/idle.js',
    '/theme.js',
    '/scripts/main.js',
    '/_astro/src/components/ThemeToggle.js',
    '/_astro/src/components/DocSidebar.js',
    '/_snowpack/pkg/@astrojs.renderer-preact.client.v0.1.3.js',
    '/_snowpack/link/workspaces/native/packages/native/src/api.js',
    '/scripts/transitions/Fade.js',
    '/scripts/transitions/BigTransition.js',
    '/scripts/transitions/Slide.js',
    '/_snowpack/pkg/preact.v10.5.14.js',
    '/_snowpack/pkg/preact.hooks.v10.5.14.js',
    '/_astro/src/components/EditOnGithub.js',
    '/_snowpack/link/workspaces/native/packages/animate/src/api.js',
    '/_snowpack/pkg/@astrojs/renderer-preact.v0.1.3/common/static-html-4514376e.js',
    '/_snowpack/link/workspaces/native/packages/native/src/config.js',
    '/_snowpack/link/workspaces/native/packages/native/src/manager.js',
    '/_snowpack/link/workspaces/native/packages/native/src/url.js',
    '/_snowpack/link/workspaces/native/packages/native/src/history.js',
    '/_snowpack/link/workspaces/native/packages/native/src/page.js',
    '/_snowpack/link/workspaces/native/packages/native/src/service.js',
    '/_snowpack/link/workspaces/native/packages/native/src/transition.js',
    '/_snowpack/link/workspaces/native/packages/native/src/app.js',
    '/_snowpack/link/workspaces/native/packages/native/src/pjax.js',
    '/_snowpack/link/workspaces/native/packages/native/src/router.js',
    '/_snowpack/link/workspaces/native/packages/animate/src/types.js',
    '/_snowpack/link/workspaces/native/packages/animate/src/utils.js',
    '/_snowpack/link/workspaces/native/packages/animate/src/builtin-effects.js',
    '/_snowpack/link/workspaces/native/packages/animate/src/css-properties.js',
    '/_snowpack/link/workspaces/native/packages/animate/src/custom-easing.js',
    '/_snowpack/link/workspaces/native/packages/animate/src/animate.js',
    '/_snowpack/link/workspaces/native/packages/animate/src/empty-tween.js',
    '/_snowpack/link/workspaces/native/packages/animate/src/stagger-and-random.js',
    '/_snowpack/link/workspaces/native/packages/animate/src/timeline.js',
    '/_snowpack/link/workspaces/native/packages/manager/src/api.js'
  ]
}

The problem is that all the _snowpack/link/workspaces/... js files are supposed to be typescript files, however, when snowpack bundles the files it treats them as js files.

Steps to reproduce

  1. Set up a linked pnpm Workspace, with one package using the workspace protocol
  2. Set the package's main file (the main file set in the package.json), to a typescript file
  3. Set up a couple different typescript files, and import them into the main file
  4. Install astro using the docs template
  5. Setup a typescript file, which imports your package
  6. Include this typescript file, in your Main.astro file
  7. Run astro build
  8. The Error stated above should occur. I expect snowpack to be able to discern typescript files and js files, and import them accordingly.

You can try it out on Gitpod,

Open In Gitpod

Link to minimal reproducible example (optional)

https://github.com/okikio/astro-build

okikio commented 3 years ago

I feel this error might be related to #3119

okikio commented 3 years ago

After some more research I've found that Snowpack requires that all linked packages be installed in the root directory. I feel either this is a bug, or this behavior is not well documented.