Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
7 tasks done
liana-p opened this issue Jul 14, 2022 · 6 comments · Fixed by #9116
Closed
7 tasks done

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

liana-p opened this issue Jul 14, 2022 · 6 comments · Fixed by #9116

Comments

@liana-p
Copy link

liana-p commented Jul 14, 2022

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

@liana-p
Copy link
Author

liana-p commented Jul 14, 2022

For example you can see the following example in the docs about building in library mode:

// vite.config.js
import { resolve } from 'path'
import { defineConfig } from 'vite'

export default defineConfig({
  build: {
    lib: {
      entry: resolve(__dirname, 'lib/main.js'),
      name: 'MyLib',
      // the proper extensions will be added
      fileName: 'my-lib'
    },
    rollupOptions: {
      // make sure to externalize deps that shouldn't be bundled
      // into your library
      external: ['vue'],
      output: {
        // Provide global variables to use in the UMD build
        // for externalized deps
        globals: {
          vue: 'Vue'
        }
      }
    }
  }
})

Which means using path is advised by the docs and should work. I tried avoiding the default import and using import { resolve } from path; but the same issue happened

@liana-p
Copy link
Author

liana-p commented Jul 14, 2022

Also worth noting, I've just managed to fix my build by updating my CI to use node 18 instead of node 15. (]Relevant PR](https://github.com/liana-p/narrat/pull/44))

I don't know if vite recommends a specific node version (couldn't find any in the docs), but before vite 3 my build worked fine on node 15 in CI, so I suppose something changed

@sapphi-red
Copy link
Member

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

@liana-p
Copy link
Author

liana-p commented 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

Right but this has to be a change in v3 that wasn't in v2 right? Because my vite config worked fine until now, it's specifically updating to v3 that broke my CI.

So all I'm saying is that this can be an unexpected a breaking change for anyone else who was doing something similar and running an older version of node

@sapphi-red
Copy link
Member

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.

@spokospace
Copy link

I have the same issue with node v14.17.5, everything works after update node to v18.6.0 :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants