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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node modules (bare specifiers) are causing an unhandled filesystem exception #43

Closed
thescientist13 opened this issue Jun 2, 2022 · 0 comments · Fixed by #44
Closed
Assignees
Labels
bug Something isn't working v0.2.2

Comments

@thescientist13
Copy link
Member

Type of Change

  • Bug

Summary

Testing in a side project, and a custom element like this

import '../components/card/card.native.js';
import fetch from 'node-fetch';

export default class ArtistsPage extends HTMLElement {
  async connectedCallback() {
    if (!this.shadowRoot) {
      const artists = await fetch('https://www.analogstudios.net/api/artists').then(resp => resp.json());
      const html = artists.map(artist => {
        return `
          <wc-card>
            <h2 slot="title">${artist.name}</h2>
            <img slot="image" src="${artist.imageUrl}" alt="${artist.name}"/>
          </wc-card>
        `;
      }).join('');

      this.attachShadow({ mode: 'open' });
      this.shadowRoot.innerHTML = html;
    }
  }
}

will cause an unhandled exception trying to use fs.readFile on node-fetch

  moduleURL: URL {
    href: 'file:///Users/owenbuckley/Workspace/project-evergreen/repos/greenwood/www/pages/node-fetch',
    origin: 'null',
    protocol: 'file:',
    username: '',
    password: '',
    host: '',
    hostname: '',
    port: '',
    pathname: '/Users/owenbuckley/Workspace/project-evergreen/repos/greenwood/www/pages/node-fetch',
    search: '',
    searchParams: URLSearchParams {},
    hash: ''
  }
}
(node:88140) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, open '/Users/owenbuckley/Workspace/project-evergreen/repos/greenwood/www/pages/node-fetch'

Details

The issue is we blindly try and read all dependencies, even bare specifiers, which are typically node modules deps and should be left to the Node resolution algorithm and not walked with acorn.


That said, this may only be a patch, since I think in the context of #38 , will we have to support walking node modules? 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working v0.2.2
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

1 participant