Skip to content

AddScriptWithoutTransform not working correctly on Linux #1292

Open
@hieucd04

Description

@hieucd04

I'm using these library versions:

  • ReactJS.NET: 5.2.12
  • JavaScriptEngineSwitcher: 3.17.4

Runtime environment:

  • OS: Linux (Ubuntu 20.04)
  • .NET Version: 6

Steps to reproduce


  1. Use this code
app.UseReact(configuration =>
{
    configuration
        .AddScriptWithoutTransform("/foo/bar/react.js");            
});
  1. Deploy to a machine running Linux OS

Actual

ReactScriptLoadException: Could not find a part of the path '<webroot>/foo/bar/react.js'

Expected

No exception thrown

More info

  • Works fine on Windows, only reproducible on Linux
  • Due to some technical limitations, I cannot place Webpack bundle in WebRoot directory

Workaround

Add \\ at the beginning of the path:

app.UseReact(configuration =>
{
    configuration
        .AddScriptWithoutTransform("\\/foo/bar/react.js");            
});

Root Cause

relativePath = relativePath.TrimStart('~').TrimStart('/').TrimStart('\\');

On Linux, TrimStart('/') is a destructive command

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions