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

[bug] can't work in an app that built by esbuild #60

Open
baurine opened this issue Apr 18, 2022 · 3 comments
Open

[bug] can't work in an app that built by esbuild #60

baurine opened this issue Apr 18, 2022 · 3 comments

Comments

@baurine
Copy link

baurine commented Apr 18, 2022

Related issue: evanw/esbuild#2181

I used a npm package sql-formatter-plus-plus in my app, the sql-formatter-plus-plus uses regexpu-core, and my app built with esbuild. it crashes when the app starts, and it reports the following error:

Uncaught Error: Failed to recognize value `undefined` for property `Alphabetic`.
    at getUnicodePropertyValueSet (rewrite-pattern.js:50:9)
    at handleLoneUnicodePropertyNameOrValue (rewrite-pattern.js:68:9)
    at getUnicodePropertyEscapeSet (rewrite-pattern.js:76:9)
    at processCharacterClass (rewrite-pattern.js:160:13)
    at processTerm (rewrite-pattern.js:205:11)
    at rewrite-pattern.js:259:12
    at Array.map (<anonymous>)
    at processTerm (rewrite-pattern.js:258:26)
    at rewrite-pattern.js:259:12
    at Array.map (<anonymous>)

The error by the following code:

try {
    return require(`regenerate-unicode-properties/${ path }.js`);
} catch (exception) {
    throw new Error(
        `Failed to recognize value \`${ value }\` for property ` +
        `\`${ property }\`.`
    );
}

esbuild can't handle the dynamic require decided in the runtime. so the author of esbuild suggest to do the following changes:

try {
  return {
    'Binary_Property/Dash': () => require(`regenerate-unicode-properties/Binary_Property/Dash.js`),
    'Binary_Property/Case_Ignorable': () => require(`regenerate-unicode-properties/Binary_Property/Case_Ignorable.js`),
    'Binary_Property/ASCII_Hex_Digit': () => require(`regenerate-unicode-properties/Binary_Property/ASCII_Hex_Digit.js`),
    'Binary_Property/Unified_Ideograph': () => require(`regenerate-unicode-properties/Binary_Property/Unified_Ideograph.js`),
    ...
  }[path]();
} catch (exception) {
  throw new Error(...);
}

How do you think about it?

Thank you!

@nicolo-ribaudo
Copy link
Collaborator

We would have to duplicate the list of property names across to different repositories, I fear that it would easily get out of sync.

As far as I know esbuild supports plugins: you could write a plugins to make it work with dynamic requires (copying Rollup's logic to work with dynamic requires).

@nicolo-ribaudo
Copy link
Collaborator

More specifically, you could use the https://esbuild.github.io/plugins/#on-load to intercept loading of this file (or of any files containing dynamic requires) and to replace the dynamic require call with a list of files reachable from that position.

@baurine
Copy link
Author

baurine commented Apr 18, 2022

hi @nicolo-ribaudo , thanks for you reply! It seems an alternative way, I will try it when I am free.

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

2 participants