Skip to content

[Bug]: Cannot build if import package name include '@' #330

@puiks

Description

@puiks

Version

npmPackages: @rslib/core: 0.0.14

Details

This is the examples of module federation, i found that would be error when i build, and i just import the button from @shopify/polaris.

import { init, loadRemote } from '@module-federation/enhanced/runtime';
import { Suspense, createElement, lazy } from 'react';
import { CounterButton } from './CounterButton';
import { useCounter } from './useCounter';
import { Button } from '@shopify/polaris'; // what i change

init({
  name: 'rslib_provider',
  remotes: [
    {
      name: 'mf_remote',
      entry: 'http://localhost:3002/mf-manifest.json',
    },
  ],
});

export const Counter: React.FC = () => {
  const { count, increment, decrement } = useCounter();

  return (
    <div>
      <Suspense fallback={<div>loading</div>}>
        {createElement(
          lazy(
            () =>
              loadRemote('mf_remote') as Promise<{
                default: React.FC;
              }>,
          ),
        )}
      </Suspense>
      <Button primary />
      <h2>
        <span id="mf-e2e-lib-title">Counter From Rslib MF Format: </span>
        <span id="mf-e2e-lib-content">{count}</span>
      </h2>
      <CounterButton id="mf-e2e-lib-decrease" onClick={decrement} label="-" />
      <CounterButton id="mf-e2e-lib-increase" onClick={increment} label="+" />
    </div>
  );
};

And this is the error when building the mf-react-componet

Image

I think it might be an invalid identifier including '@' symbol, but how to solve that, could you please help review this?

Reproduce link

n

Reproduce Steps

  1. cd examples/module-federation/mf-react-component
  2. yarn add @[email protected]
  3. add import {Button} from '@shopify-polaris' into the index.tsx
  4. yarn build

Metadata

Metadata

Assignees

Labels

🐞 bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions