Skip to content

Compatiblity issue with Create React App not allow import outside of src/ #37

@bwv850

Description

@bwv850

Background: Create React App comes with a ModuleScopePlugin which ensures that relative imports from app's source directories don't reach outside of it, meaning whatever you're importing has to be either in src/ or node_modules.

But our plugin node-polyfill-webpack-plugin uses webpack require.resolve, which returns the absolute path of packages

image

If we trying to use console or path polyfill with CRA

function App() {
  console.log('Hello world');
  path.join('./assets/img', 'logo.png');
  
  return (
    <div className="App">
    ....
    </div>
  );
}

CRA would report error

image

I created a reproduce repository here node-polyfill-webpack-plugin-cra-reproduce

Some other info

  • yarn version: 1.22.15
  • node version: v16.16.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions