Skip to content

Importing roslib in Vite application crashes in production as 'this' is undefined #838

Open
@olehakon

Description

@olehakon

Description
I'm using Vite to build a React SPA, hosted through a Node Express server.

Importing roslib in dev mode works, but after building the application I have an error in the browser saying Cannot read properties of undefined (reading 'ROSLIB').

The error seems to come from the RosLib.js file, specifically this code:

var ROSLIB = this.ROSLIB || {  // <-- Error here
   REVISION : '1.4.1'
};

It seems that 'this' is undefined.

Am I missing something here or is this module not compatible with Vite?

  • Library Version: 1.4.1
  • ROS Version: ?
  • Platform / OS: OSX

Steps To Reproduce

  1. Create a new Vite project
  2. Install roslib
  3. import roslib, e.g. import * as ROS from "roslib"
  4. Build the application for production and run it

Expected Behavior
Application running as expected

Actual Behavior
Application crashes with the follwing error:

Uncaught TypeError: Cannot read properties of undefined (reading 'ROSLIB')

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions