Paciolan / remote-component

Dynamically load a React Component from a URL
MIT License
591 stars 49 forks source link

A weird warning? Can't resolve 'remote-component.config.js' #71

Open addlistener opened 1 month ago

addlistener commented 1 month ago

The problem

The remote components loads successfully, however I get the following error in terminal

 ⚠ ./node_modules/@paciolan/remote-component/dist/getDependencies.js
Module not found: Can't resolve 'remote-component.config.js' in './node_modules/@paciolan/remote-component/dist'

Import trace for requested module:
./node_modules/@paciolan/remote-component/dist/getDependencies.js
./node_modules/@paciolan/remote-component/dist/index.js

More details

The complaining code

var getDependencies = function () {
    try {
        // eslint-disable-next-line @typescript-eslint/no-var-requires
        return exports.ensureRemoteComponentConfig(require("remote-component.config.js"));
    }
    catch (err) {
        // istanbul ignore next: This is just too impossible to test
        if (!cannotFindModule(err)) {
            throw err;
        }
        return {};
    }
};
exports.getDependencies = getDependencies;
//# sourceMappingURL=getDependencies.js.map

This is how I've been using remote-component

import { resolve } from '../../../../../remote-component.config.cjs';

// @ts-expect-error it's cjs code
const requires = createRequires(resolve);
export const useRemoteComponent = createUseRemoteComponent({ requires });

I tried to change cjs to js but the warning persists. So I changed it back. And since I've loaded remote-component manually why the code tries to load the config.reoslve again?

smeng9 commented 1 month ago

You need to put this file under your own project's root folder

addlistener commented 1 month ago

I tried again. It's in my own project's root folder. The warning persists.

And the function runs without problem which means this complaint is useless?

You need to put this file under your own project's root folder