Home / Blog / The CJS build of Vite’s Node API is deprecated
The CJS build of Vite’s Node API is deprecated

The CJS build of Vite’s Node API is deprecated

Daniel Kelly
Daniel Kelly
February 29th 2024

If you’re upgrading an exiting Vue project that uses Vite you may have run into this warning when starting the dev server:

The CJS build of Vite's Node API is deprecated. 

The provided link gives you a great step by step on how to resolve the issue. For most projects it’s as simple as adding the following to your package.json file:

"type": "module",

However, some projects have defined their import alias as follows in vite.config.js. This uses the Common JS path.resolve and is therefore incompatible with ESM.

alias:{
  '@' : path.resolve(__dirname, './src')
},

In fact, this is how we originally suggested users enable the import aliases in this article (though we’ve since updated it to the proper ESM syntax).

In order to work with the latest version of Vite you MUST remove the common JS syntax otherwise your aliases won’t work. Checkout this article for the updated syntax to ensure your import aliases continue to work!

Also, if you are interested in learning more about how to utilize Vite for your own Vue.js projects, checkout our course Rapid Development with Vite. In the course, we talk about all kinds of Vite features like: CSS modules, glob imports, CSS pre-processors, images with Vite, and more!

Start learning Vue.js for free

Daniel Kelly
Daniel Kelly
Daniel is the lead instructor at Vue School and enjoys helping other developers reach their full potential. He has 10+ years of developer experience using technologies including Vue.js, Nuxt.js, and Laravel.

Latest Vue School Articles

Automatic File-Based Routing in Vue.js with TypeScript Support

Automatic File-Based Routing in Vue.js with TypeScript Support

This article introduces you to the exciting world of Automatic File-Based Routing in Vue.js 3 using unplugin-vue-router. Say goodbye to verbose router configuration files and embrace a more intuitive, maintainable, and developer-friendly way to define your application's routes.
Mostafa Said
Mostafa Said
Enhanced Routing with UnPlugin Vue Router

Enhanced Routing with UnPlugin Vue Router

Are you ready to take enhance your experience with Vue Router? Look no further than our latest course Enhanced Routing with UnPlugin Vue Router. During the course, we cover how to do everything you already know with vanilla Vue Router but in a type-safe manner and with file-based routing.
Daniel Kelly
Daniel Kelly

Our goal is to be the number one source of Vue.js knowledge for all skill levels. We offer the knowledge of our industry leaders through awesome video courses for a ridiculously low price.

More than 120.000 users have already joined us. You are welcome too!

Follow us on Social

© All rights reserved. Made with ❤️ by BitterBrains, Inc.