Skip to content

vite dev fails when using a local commonjs module #7138

@UltiRequiem

Description

@UltiRequiem

Describe the bug

I have a package.json like

{
  "name": "use-github-react-js",
  "private": true,
  "version": "0.0.0",
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "preview": "vite preview"
  },
  "dependencies": {
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "use-github": "file:../.."
  },
  "devDependencies": {
    "@vitejs/plugin-react": "^1.0.7",
    "vite": "^2.8.0"
  }
}

The important part is where I import use-github, it's being defined like that because the project is located in an example directory, it's important to mention that this project is not a monorepo!

Reproduction

https://github.com/UltiRequiem/use-github/tree/main/examples/use-github-react-js

System Info

System:
    OS: Linux 5.16 Arch Linux
    CPU: (8) x64 Intel(R) Core(TM) i5-1035G1 CPU @ 1.00GHz
    Memory: 12.17 GB / 15.42 GB
    Container: Yes
    Shell: 5.8.1 - /usr/bin/zsh
  Binaries:
    Node: 17.6.0 - /usr/bin/node
    Yarn: 1.22.15 - /usr/bin/yarn
    npm: 8.5.2 - /usr/bin/npm
  Browsers:
    Brave Browser: 98.1.35.103
    Firefox: 97.0.1

Used Package Manager

pnpm

Logs

The problem occurs on the browser, the build is successful

Uncaught ReferenceError: exports is not defined
    at index.js:16:23

index.js

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
    for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./user"), exports);
__exportStar(require("./pinned-repos"), exports);

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions