How to serve netlifycms.js from node_modules to a page using next?

I have installed netlify via npm, now there’s its script sitting inside node_modules.

I need it to be in the head, e.g. <script src="node_modules/..."/> for admin page; I know how to use “next/head”.

But Next doesn’t serve from “node_modules” folder. Requiring that script gives “window not defined” error—it’s browser-only script. Also, as I am statically hosting this site, node_modules isn’t even part of final bundle…

Please help. Latest NextJS version used.

PS. Currently, I am adding netlifycms from unpkg, but want it to be part of package.json to be able to update.

Actually, the version on unpkg is always updated, so you don’t need to worry about updating it yourself.
If you import the script through npm, you’ll have to create a cms.js file with the following content:

import CMS from 'netlify-cms-app';


I wouldn’t advise to include this in your websites’ regular javascript file, as the CMS resource is pretty large. You could use webpack to split the files into seperate entries like I’ve done here. Loading the script through unpkg is still far easier though. You can have a look at this example, or follow the NextJS guide here.

Thanks! I will try this approach.

Also, the approach from sample results an ugly “site/admin/index.html” route, since Next doesn’t serve index.html from subfolders, and “site/admin” is 404…