Skip to content

[V3] Error on build in CI: Cannot find module 'node:path' in vite.config.ts #9113

Closed
@liana-p

Description

@liana-p

Describe the bug

As Vite v3 is released, I've updated my project to use it. However, I am getting a new error when building in CI (GitHub workflows).

The error is Error: Cannot find module 'node:path' which seems to mean that the build isn't running in a node environment. However this script used to run fine on CI without any changes. Updating to Vite 3 made it break.

My vite.config.ts file uses node's path.resolve which I found advised somewhere in docs in regards to using the lib mode I think. It was a while ago. Relevant bit of the config:

      lib: {
        entry: path.resolve(__dirname, 'src/lib/lib.ts'),
        name: 'narrat',
        fileName: (format) => `narrat.${format}.js`,
      },

It seems using node's path module breaks, whereas it didn't before updating to v3.

In the reproduction link, I put a link to the GitHub workflow that failed.

Reproduction

https://github.com/liana-p/narrat/runs/7337553246?check_suite_focus=true

System Info

Using vite v3 and a config in TypeScript. The build is running in GitHub CI (Ubuntu, [see workflow config](https://github.com/liana-p/narrat/blob/v2.1.0/.github/workflows/main.yml))

Used Package Manager

npm

Logs

Run npm run build --if-present

narrat@2.1.0 build
vue-tsc --noEmit && vite build && npm run generate-types
failed to load config from /home/runner/work/narrat/narrat/vite.config.ts
error during build:
Error: Cannot find module 'node:path'
Require stack:

  • /home/runner/work/narrat/narrat/node_modules/vite/dist/node-cjs/publicUtils.cjs
  • /home/runner/work/narrat/narrat/node_modules/vite/index.cjs
  • /home/runner/work/narrat/narrat/vite.config.ts
  • /home/runner/work/narrat/narrat/node_modules/vite/dist/node/chunks/dep-561c5231.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15)
    at Function.Module._load (node:internal/modules/cjs/loader:769:27)
    at Module.require (node:internal/modules/cjs/loader:996:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at Object. (/home/runner/work/narrat/narrat/node_modules/vite/dist/node-cjs/publicUtils.cjs:5:14)
    at Module._compile (node:internal/modules/cjs/loader:1092:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
    at Object._require.extensions..js (file:///home/runner/work/narrat/narrat/node_modules/vite/dist/node/chunks/dep-561c5231.js:62742:13)
    at Module.load (node:internal/modules/cjs/loader:972:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    Error: Process completed with exit code 1.

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