web-infra-dev / rspack

The fast Rust-based web bundler with webpack-compatible API 🦀️
https://rspack.dev
MIT License
8.57k stars 503 forks source link

Failed to resolve xxx in project root error occurred while using inputFileSystem #5091

Open MrToy opened 8 months ago

MrToy commented 8 months ago

System Info

System: OS: macOS 14.0 CPU: (12) arm64 Apple M2 Max Memory: 387.53 MB / 64.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 19.9.0 - ~/.nvm/versions/node/v19.9.0/bin/node npm: 9.6.3 - ~/.nvm/versions/node/v19.9.0/bin/npm pnpm: 7.15.0 - ~/.nvm/versions/node/v19.9.0/bin/pnpm Browsers: Chrome: 120.0.6099.109 Safari: 17.0 npmPackages: @rspack/core: ^0.4.4 => 0.4.4

Details

I'm trying to bundle my project using a virtual file system.

Here is my code.

import { rspack } from "@rspack/core";
import { Volume, createFsFromVolume } from "memfs";
  const files = {
    "/index.tsx": `
    import React from 'react';
    import ReactDOM from 'react-dom';
    ReactDOM.render(<div></div> , document.getElementById("root"));`,
  };
  const val = Volume.fromJSON(files);
  const fs = createFsFromVolume(val);
  const compiler = rspack({
    mode: "production",
    entry: "/index.tsx",
    output: {
      filename: "/ouput.js",
    }
  });
  compiler.inputFileSystem = fs;
  compiler.intermediateFileSystem = fs;
  //@ts-ignore
  compiler.outputFileSystem = fs;

  compiler.run((err, result) => {
    const files = val.toJSON();
    console.log(err, result, files);
  });

Here is error message

ERROR in × Failed to resolve /index.tsx in project root

Reproduce link

No response

Reproduce Steps

It can be reproduced by running the code I provided.

hardfist commented 8 months ago

@Boshen does oxc_resolver supports passing custom filesystem now?

It seems oxc_resolver supports filesystem, but Rspack resolve options doesn't support pass filesystem to oxc_resolver yet

Boshen commented 8 months ago

To support this use case, Rspack needs to implement ResolverGeneric from oxc_resolver with its own implementation of FileSystem, and expose the relevant APIs to the JS side.

xc2 commented 8 months ago

The last time I tried to work with inputFileSystem, I realized that rspack only use .purge method of it.

therefore I think rspack hasn't been ready for inputFileSystem. pls correct me if i got the thing wrong.

hardfist commented 8 months ago

The last time I tried to work with inputFileSystem, I realized that rspack only use .purge method of it.

therefore I think rspack hasn't been ready for inputFileSystem. pls correct me if i got the thing wrong.

since inputFileSystem is a public API, other Rspack|Webpck plugin may use other method in it.

xc2 commented 8 months ago

The last time I tried to work with inputFileSystem, I realized that rspack only use .purge method of it. therefore I think rspack hasn't been ready for inputFileSystem. pls correct me if i got the thing wrong.

since inputFileSystem is a public API, other Rspack|Webpck plugin may use other method in it.

i mean that rspack doesn't utilize inputFileSystem for reading file system.

Previously, i used to create memfs as inputFileSystem and outputFileSystem for unit testing purposes. This allowed me to avoid generating numerous fixture files in my repository or pay effort at cleaning up test artifacts after testing

However, when I attempted to do the same with rspack, I noticed that the outputFileSystem worked as expected while the inputFileSystem didn't

hardfist commented 8 months ago

because Rspack read outputFilesystem and not read inputFilesystem in Rust side yet, see https://github.com/web-infra-dev/rspack/blob/main/crates/node_binding/src/lib.rs#L68

xc2 commented 8 months ago

because Rspack read outputFilesystem and not read inputFilesystem in Rust side yet, see https://github.com/web-infra-dev/rspack/blob/main/crates/node_binding/src/lib.rs#L68

i see - i believe this issue is also this thing.

hardfist commented 8 months ago

@xc2 do you want to give it a try to implement this feature?

xc2 commented 8 months ago

@xc2 do you want to give it a try to implement this feature?

hard to promise as i'm quite new to rust. previous i had a hard time to impl module.noParse, still being blocked by a runtime panic to do with the js function call in rust.

i will still give it a try but it is supposed to be long.

hardfist commented 8 months ago

It's not an urgent feature, so take your time, and if you met problems when contributing to Rspack, feel free to ping us

stale[bot] commented 6 months ago

This issue has been automatically marked as stale because it has not had recent activity. If this issue is still affecting you, please leave any comment (for example, "bump"). We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

xc2 commented 6 months ago

bump

stale[bot] commented 3 months ago

This issue has been automatically marked as stale because it has not had recent activity. If this issue is still affecting you, please leave any comment (for example, "bump"). We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

zackarychapple commented 2 months ago

bump

stale[bot] commented 1 week ago

This issue has been automatically marked as stale because it has not had recent activity. If this issue is still affecting you, please leave any comment (for example, "bump"). We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

Justinidlerz commented 1 week ago

bump