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

Dynamic require conflict with packagers #67

Open
PRR24 opened this issue May 24, 2024 · 8 comments
Open

Dynamic require conflict with packagers #67

PRR24 opened this issue May 24, 2024 · 8 comments

Comments

@PRR24
Copy link

PRR24 commented May 24, 2024

Added
... require("tty").isatty(1) ...
in version 1.0.1 results Angular compiler warning
./node_modules/picocolors/picocolors.js:3:163-170 - Warning: Critical dependency: require function is used in a way in which dependencies cannot be statically extracted.

Would be great if it was solved differently.

@alexeyraspopov
Copy link
Owner

@PRR24 is it your Angular app code that imports picocolors? How did the compiler end up parsing code of the library?

@PRR24
Copy link
Author

PRR24 commented May 29, 2024

There are number of indirect dependencies to picocolor from @angular-devkit/build-angular
Not sure which one of those specificly causes the issue to appear.

@PRR24
Copy link
Author

PRR24 commented May 29, 2024

Forgot to specify that the my issue appears with Angular 16.latest SSR build.

@belgattitude
Copy link

Got it also with latest nextjs app router when using kysely. Couldn't reproduce easily on an opensource repo, but the issue seems to exist

@someshwar-terkar
Copy link

Hey, any update on this issue?

@alexeyraspopov
Copy link
Owner

It should be an easy fix, I can probably get to it this week. Though I would still appreciate some info about how dis you end up in situation where the angular compiler started analyzing this dependency

@PRR24
Copy link
Author

PRR24 commented Jun 3, 2024

I think Angular has had the dependency for a long time. There are no issues with picocolors@1.0.0, which I forced my project to at this point.

If I would make a bold guess, I think the issue is arised from
@angular-devkit/build-angular -> @babel/core -> @babel/code-frame -> picocolors dependency.
But again, this is just a guess, no facts.

@readikus
Copy link

It should be an easy fix, I can probably get to it this week. Though I would still appreciate some info about how dis you end up in situation where the angular compiler started analyzing this dependency

Unfortunately, I can't seem to recreate this issue in a separate repo, so it's a challenge to share it.

My current project is a nextjs project, and the issue I am seeing in the console is:

Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

Import trace for requested module:
./node_modules/picocolors/picocolors.js
./node_modules/@babel/code-frame/lib/index.js
./node_modules/html-validate/dist/es/browser.js
./src/my-file.ts

The related part of my-file is this:

import { HtmlValidate, Result, StaticConfigLoader } from 'html-validate/browser';

const createHtmlValidator = () => {
  const loader = new StaticConfigLoader({
    extends: ['html-validate:standard'],
    elements: ['html5'],
  });
  return new HtmlValidate(loader);
};

const isValidHTML = async (html: string, validator: HtmlValidate): Promise<boolean> => {
  try {
    const report = await validator.validateString(html);
    return report.valid;
  } catch (error) {
    console.error('ERROR VALIDATING HTML:', error);
    return false;
  }
};

export const validateHTML = async (html: string): Promise<Result[]> => {
  try {
    const validator = createHtmlValidator();
    const report = await validator.validateString(html);
    return report.results;
  } catch (error) {
    console.error('ERROR VALIDATING HTML:', error);
    return [];
  }
};

This may be completely unhelpful, but I ended up on this page, and spent some time trying to build a clean nextjs project to recreate this issue, and sadly that didn't reproduce the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants