iLib-js / iLib

A library of i18n routines written in Javascript.
Apache License 2.0
35 stars 4 forks source link

[ASTRO.JS] [VITE] [ENACT] [ILIB] Could not resolve "./lib/ilib-qt.js" #449

Closed lrembacz closed 10 months ago

lrembacz commented 10 months ago

When building AstroJS app with @enact/sandstone I'm getting errors like:

`X [ERROR] Could not resolve "./lib/ilib-qt.js"

node_modules/ilib/index.js:1:359:
  1 │ ..."webos-webapp":break;case"webos":case"nodejs":require("./lib/ilib-node.js");break;case"qt":require("./lib/ilib-qt.js");break;case"rhino":require("./lib/ilib-rhino.js");break;case"ringo":require("./lib/ilib-ringo.js"... 
    ╵                                                                                                       ~~~~~~~~~~~~~~~~~~

X [ERROR] Could not resolve "./lib/ilib-rhino.js"

node_modules/ilib/index.js:1:405:
  1 │ ...quire("./lib/ilib-node.js");break;case"qt":require("./lib/ilib-qt.js");break;case"rhino":require("./lib/ilib-rhino.js");break;case"ringo":require("./lib/ilib-ringo.js");break;default:ilib._dyncode=!1,ilib._dyndata=!... 
    ╵                                                                                                     ~~~~~~~~~~~~~~~~~~~~~

X [ERROR] Could not resolve "./lib/ilib-ringo.js"

node_modules/ilib/index.js:1:454:
  1 │ ...ode.js");break;case"qt":require("./lib/ilib-qt.js");break;case"rhino":require("./lib/ilib-rhino.js");break;case"ringo":require("./lib/ilib-ringo.js");break;default:ilib._dyncode=!1,ilib._dyndata=!1}module.exports=ilib; 
    ╵                         `

dependencies looks like this:

"dependencies": { "@astrojs/react": "^3.0.4", "@enact/core": "^4.7.6", "@enact/i18n": "^4.7.6", "@enact/sandstone": "^2.7.12", "@enact/spotlight": "^4.7.6", "@enact/ui": "^4.7.6", "@types/react": "^18.2.35", "@types/react-dom": "^18.2.14", "astro": "^3.4.3", "ilib": "^14.18.0", "react": "^18.2.0", "react-dom": "^18.2.0" }

In node_modules/ilib there is no such files, so they can't be resolved. Can you help with it somehow?

ehoogerbeets commented 10 months ago

Hi @lrembacz , the missing js files are for environments that you are not using, so it is safe to ignore them. You can create a build plugin for Astro to exclude those files from the build. Something like this:

// exclude-module-plugin.js
export default function excludeModulePlugin() {
  return {
    name: 'exclude-module-plugin',
    resolveId(id) {
      // Exclude the specific module you want to ignore
      if (id === './lib/ilib-qt.js' || id === './ilib/ilib-rhino.js' ||  [etc]  ) {
        return false;
      }
    }
  };
}

Then update your astro.config.js to add this plugin to the "build.plugins" array.

lrembacz commented 10 months ago

Unluckly it is not working. Those files are not even processed by this plugin, so it should be something different i guess.

I've pushed repository to github, so you can check yourself https://github.com/lrembacz/astro-ilib-error.

I have tried to use externals as well, but it doesn't seem to work either.

ehoogerbeets commented 10 months ago

I'm not really too sure how Astro works, as I have never used it before. (ChatGPT helped me make the suggestion for the excludeModulePlugin!) You can find the missing ilib files in the ilib sources.

I am thinking that we can ship those extra ilib-.js files along with the npm package, even though they will never be used. It can't hurt if it is not used and the files are small and it will make the bundler for Astro work.

For now, you can create some empty files node_modules/ilib/lib/ilib-qt.js, node_modules/ilib/lib/ilib-rhino.js, etc. See if it works with those..

lrembacz commented 10 months ago

Okey. I have tried to make it work, but there are more issues with that. Thanks for help!