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

@module-federation/node __dirname #1467

Closed
RussianDragon opened this issue Sep 28, 2023 · 8 comments
Closed

@module-federation/node __dirname #1467

RussianDragon opened this issue Sep 28, 2023 · 8 comments

Comments

@RussianDragon
Copy link

RussianDragon commented Sep 28, 2023

Hi.
I have two problems with __dirname, for @module-federation/node version 1.0.7.

  1. Before update version (from 0.14.0 to 1.0.7) in __dirname, in shell project, correctly keeped path to execution directory. Now __dirname point to root directory (inside use code). It is bug or i need use different parameter?

Me need to __dirname for express:

const appsettings = JSON.parse(
  fs.readFileSync(path.join(__dirname, 'settings.json'), 'utf-8'),
) as IAppSettingsShell;
  1. I need read resource json file from in module. What parameter me need to use for correctly path to file?
@ScriptedAlchemy
Copy link
Member

are you trying to read from the hosts local directory? via a remote?

Can you try the latest prerelease on npm, under the "next" tag

@ScriptedAlchemy
Copy link
Member

Ive found the problem, looks related to something in the node plugin targeting system (i think)

#1268 solves it (i just encountered this and fixed) but its attached to a much larger PR which isnt releasing yet.

@RussianDragon
Copy link
Author

RussianDragon commented Sep 29, 2023

Ive found the problem, looks related to something in the node plugin targeting system (i think)

#1268 solves it (i just encountered this and fixed) but its attached to a much larger PR which isnt releasing yet.

If I understand correctly, I need to wait for the merge :)
Ok.


For information. Maybe you will be interested
Using your library, we have developed two large packages for our system.
Installation from a template
npx clear-npx-cache
npx @quantumart/qp8-widget-platform-shell my-shell
npx @quantumart/qp8-widget-platform-module my-module

Or git hub links
QA.WidgetPlatform.Shell
QA.WidgetPlatform.Module

I convert build to TypeScript, and clear extra @babel library.
webpack.config._.js

presets: [['@babel/preset-react', { runtime: 'automatic' }], '@babel/preset-typescript'],

Formally, there are two problems left:

  1. Dynamic loading of files by the project module on the server.
  2. And dynamic loading of project-module of server rendering. I wrote about this problem earlier. And I hope to solve it through new versions of your library.

Thank you

@ScriptedAlchemy
Copy link
Member

You can do dynamic loading on server: https://github.com/module-federation/module-federation-examples/tree/master/dynamic-remotes-node

My utilities work univerally as they all use low level webpack runtime apis, so we hook into the same thing webpack statically does at compile.

Ill need to verify it still works as expected with the new rewrites in that PR youre waiting on. I may publish a new pre-release to npm today so just look out for "next" tag on the package you want on npm and there should ne a new update soon

@RussianDragon
Copy link
Author

RussianDragon commented Oct 3, 2023

Ill need to verify it still works as expected with the new rewrites in that PR youre waiting on. I may publish a new pre-release to npm today so just look out for "next" tag on the package you want on npm and there should ne a new update soon

For version ^2.0.2-beta.3 don't have npm https://www.npmjs.com/package/@swc/helpers

webpack-cli] Failed to load 'C:\Repostories\qp8-widget-platform-module\template\config\webpack.config.client.server.modules.local._.js' config
[webpack-cli] Error: Cannot find module '@swc/helpers/_/_interop_require_default'
Require stack:
- C:\Repostories\qp8-widget-platform-module\template\node_modules\@module-federation\enhanced\src\index.js
- C:\Repostories\qp8-widget-platform-module\template\node_modules\@module-federation\node\src\plugins\NodeFederationPlugin.js
- C:\Repostories\qp8-widget-platform-module\template\node_modules\@module-federation\node\src\index.js
- C:\Repostories\qp8-widget-platform-module\template\config\module-federation.js
- C:\Repostories\qp8-widget-platform-module\template\config\webpack.config.client._.js
- C:\Repostories\qp8-widget-platform-module\template\config\webpack.config.client.server.modules._.js
- C:\Repostories\qp8-widget-platform-module\template\config\webpack.config.client.server.modules.local._.js
- C:\Repostories\qp8-widget-platform-module\template\node_modules\webpack-cli\lib\webpack-cli.js
- C:\Repostories\qp8-widget-platform-module\template\node_modules\webpack-cli\lib\bootstrap.js
- C:\Repostories\qp8-widget-platform-module\template\node_modules\webpack-cli\bin\cli.js
- C:\Repostories\qp8-widget-platform-module\template\node_modules\webpack\bin\webpack.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1075:15)
    at Module._load (node:internal/modules/cjs/loader:920:27)
    at Module.require (node:internal/modules/cjs/loader:1141:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at Object.<anonymous> (C:\Repostories\qp8-widget-platform-module\template\node_modules\@module-federation\enhanced\src\index.js:34:34)
    at Module._compile (node:internal/modules/cjs/loader:1254:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Module._load (node:internal/modules/cjs/loader:958:12)
    at Module.require (node:internal/modules/cjs/loader:1141:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\Repostories\\qp8-widget-platform-module\\template\\node_modules\\@module-federation\\enhanced\\src\\index.js',
    'C:\\Repostories\\qp8-widget-platform-module\\template\\node_modules\\@module-federation\\node\\src\\plugins\\NodeFederationPlugin.js',
    'C:\\Repostories\\qp8-widget-platform-module\\template\\node_modules\\@module-federation\\node\\src\\index.js',
    'C:\\Repostories\\qp8-widget-platform-module\\template\\config\\module-federation.js',
    'C:\\Repostories\\qp8-widget-platform-module\\template\\config\\webpack.config.client._.js',
    'C:\\Repostories\\qp8-widget-platform-module\\template\\config\\webpack.config.client.server.modules._.js',
    'C:\\Repostories\\qp8-widget-platform-module\\template\\config\\webpack.config.client.server.modules.local._.js',
    'C:\\Repostories\\qp8-widget-platform-module\\template\\node_modules\\webpack-cli\\lib\\webpack-cli.js',
    'C:\\Repostories\\qp8-widget-platform-module\\template\\node_modules\\webpack-cli\\lib\\bootstrap.js',
    'C:\\Repostories\\qp8-widget-platform-module\\template\\node_modules\\webpack-cli\\bin\\cli.js',
    'C:\\Repostories\\qp8-widget-platform-module\\template\\node_modules\\webpack\\bin\\webpack.js'
  ]
}

@RussianDragon
Copy link
Author

RussianDragon commented Oct 3, 2023

After install package @swc/helpers. for both project, I have new exception for version 2.0.2-beta.3
It not fond fn function on server [browser worked correct] text_page - it is endpoint (exposes) for module qp_widgets_platform_modules.

TypeError: fn is not a function
while loading "./text_page" from webpack/container/reference/qp_widgets_platform_modules
    at handleFunction (C:\Repostories\qp8-widget-platform-shell\template\dist\server\main.js:397:31)
    at onInitialized (C:\Repostories\qp8-widget-platform-shell\template\dist\server\main.js:409:60)
    at handleFunction (C:\Repostories\qp8-widget-platform-shell\template\dist\server\main.js:402:25)
    at onExternal (C:\Repostories\qp8-widget-platform-shell\template\dist\server\main.js:408:68)
    at handleFunction (C:\Repostories\qp8-widget-platform-shell\template\dist\server\main.js:402:25)
    at C:\Repostories\qp8-widget-platform-shell\template\dist\server\main.js:416:15
    at Array.forEach (<anonymous>)
    at __webpack_require__.f.remotes (C:\Repostories\qp8-widget-platform-shell\template\dist\server\main.js:379:36)
    at C:\Repostories\qp8-widget-platform-shell\template\dist\server\main.js:295:40
    at Array.reduce (<anonymous>)
var handleFunction = (fn, arg1, arg2, d, next, first) => {
/******/ 						try {
/******/ 							var promise = fn(arg1, arg2);
/******/ 							if(promise && promise.then) {
/******/ 								var p = promise.then((result) => (next(result, d)), onError);
/******/ 								if(first) promises.push(data.p = p); else return p;
/******/ 							} else {
/******/ 								return next(promise, d, first);
/******/ 							}
/******/ 						} catch(error) {
/******/ 							onError(error);
/******/ 						}
/******/ 					}
var onInitialized = (_, external, first) => {
  console.log("external", external);
  return (handleFunction(external.get, data[1], getScope, 0, onFactory, first))
  };

external {}

@RussianDragon
Copy link
Author

RussianDragon commented Oct 3, 2023

You can do dynamic loading on server: https://github.com/module-federation/module-federation-examples/tree/master/dynamic-remotes-node

My utilities work univerally as they all use low level webpack runtime apis, so we hook into the same thing webpack statically does at compile.

Thank you. I try use injectScript for configuration:

    "@module-federation/node": "^0.14.0",
    "@module-federation/utilities": "^1.5.0",

but I have an exception because the library search for the file "Logger.js" inside my source folder and not inside the package.

WARNING in ./node_modules/@module-federation/utilities/src/Logger.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from 'C:\Repostories\qp8-widget-platform-shell\template\packages\utilities\src\Logger.ts' file: Error: ENOENT: no such file or directory, open 'C:\Repostories\qp8-widget-platform-shell\template\packages\utilities\src\Logger.ts'
 @ ./node_modules/@module-federation/utilities/src/index.js 8:21-40
 @ consume shared module (default) @module-federation/utilities@^1.5.0 (strict) (fallback: ./node_modules/@module-federation/utilities/src/index.js)
 @ ./src/share/stores/wp-components/realizations/dynamic-wpc-store.tsx 5:0-60 81:49-61
 @ ./src/server/render.tsx 17:0-105 24:63-87
 @ ./src/server/bootstrap.tsx 54:33-51
 @ ./src/server/index.ts 1:0-21

@ScriptedAlchemy
Copy link
Member

ive release newer prereelases that my help with this now, my CI has some issues and caused bad released to go out

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