question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.<anonymous> (/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

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

11reactions
sapphi-redcommented, Jul 14, 2022

Vite uses node: import which is supported in v16.0.0+ and v14.18.0+. v15 does not support this. https://nodejs.org/api/esm.html#node-imports

4reactions
sapphi-redcommented, Jul 14, 2022

Yes, this is a change introduced in v3. This was forgotten to mention in docs/migration guide.

This is a intended breaking change because node 15 is already EOL.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot find module 'node:path' in vite.config.ts - 面向对象爱好 ...
Vue3 Error on build in CI: Cannot find module 'node:path' in ... 包 rm -rf node_modules package-lock.json 再 npm i ,再build 就没有问题了。
Read more >
[V3] Error on build in CI: Cannot find module 'node:path' in vite ...
原来的自己的node 版本是v14.16.0 的版本,出现了不兼容的问题,于是升级到了稳定版v16.16.0。,再build 就没有问题了。
Read more >
How do I resolve "Cannot find module" error using Node.js?
Using npm install installs the module into the current directory only (in a subdirectory called node_modules ). Is app.js located under ...
Read more >
Failed to load config from vite.config.js - Laracasts
vite build failed to load config from /Users/Sites/hub/vite.config.js error during build: Error: Cannot find module 'node:path' Require stack: ...
Read more >
Troubleshooting - Vite
Error : Cannot find module 'C:\foo\bar&baz\vite\bin\vite.js' #. The path to your project folder may include & , which doesn't work with npm on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found