Depoy buildfails when Netlify CLI installed as dev dep

https://app.netlify.com/sites/wai-course-list/deploys/625eeab3b570ef386577bfe5

I locally installed Netlify CLI as a dev dep as instructed in order tod locally debug functions. However it seems to be installed as part of the pre build and throws ESM errors. I do not expect dev deps to get installed and do not want to add/remove each time I debug. I tried using my global netlify CLI but could not get the VSCode config right.

> @netlify/esbuild@0.13.6 postinstall /opt/build/repo/node_modules/netlify-cli/node_modules/@netlify/esbuild
6:03:53 PM: > node install.js
6:03:54 PM: > core-js@2.6.12 postinstall /opt/build/repo/node_modules/netlify-cli/node_modules/core-js
6:03:54 PM: > node -e "try{require('./postinstall')}catch(e){}"
6:03:54 PM: > netlify-cli@10.0.0 postinstall /opt/build/repo/node_modules/netlify-cli
6:03:54 PM: > node ./scripts/postinstall.js
6:03:56 PM: Success! Netlify CLI has been installed!
6:03:56 PM: Your device is now configured to use Netlify CLI to deploy and manage your Netlify sites.
6:03:56 PM: Next steps:
6:03:56 PM:   netlify init     Connect or create a Netlify site from current directory
6:03:56 PM:   netlify deploy   Deploy the latest changes to your Netlify site
6:03:56 PM: For more information on the CLI run netlify help
6:03:56 PM: Or visit the docs at https://cli.netlify.com
6:03:56 PM: (node:2114) ExperimentalWarning: The ESM module loader is experimental.
6:03:56 PM: Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only file and data URLs are supported by the default ESM loader
6:03:56 PM:     at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:720:11)
6:03:56 PM:     at Loader.resolve (internal/modules/esm/loader.js:97:40)
6:03:56 PM:     at Loader.getModuleJob (internal/modules/esm/loader.js:243:28)
6:03:56 PM:     at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:42:40)
6:03:56 PM:     at link (internal/modules/esm/module_job.js:41:36) {
6:03:56 PM:   code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME'
6:03:56 PM: }
6:03:56 PM: Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only file and data URLs are supported by the default ESM loader
6:03:56 PM:     at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:720:11)
6:03:56 PM:     at Loader.resolve (internal/modules/esm/loader.js:97:40)
6:03:56 PM:     at Loader.getModuleJob (internal/modules/esm/loader.js:243:28)
6:03:56 PM:     at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:42:40)
6:03:56 PM:     at link (internal/modules/esm/module_job.js:41:36) {
6:03:56 PM:   code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME'
6:03:56 PM: }
6:03:56 PM: /opt/build/repo/node_modules/netlify-cli/node_modules/netlify-redirector/lib/redirects.js:116
6:03:56 PM:       throw ex;
6:03:56 PM:       ^
6:03:56 PM: abort({"code":"ERR_UNSUPPORTED_ESM_URL_SCHEME"}) at Error
6:03:56 PM:     at jsStackTrace (/opt/build/repo/node_modules/netlify-cli/node_modules/netlify-redirector/lib/redirects.js:1070:13)
6:03:56 PM:     at stackTrace (/opt/build/repo/node_modules/netlify-cli/node_modules/netlify-redirector/lib/redirects.js:1087:12)
6:03:56 PM:     at process.abort (/opt/build/repo/node_modules/netlify-cli/node_modules/netlify-redirector/lib/redirects.js:8502:44)
6:03:56 PM:     at process.emit (events.js:315:20)
6:03:56 PM:     at process.EventEmitter.emit (domain.js:482:12)
6:03:56 PM:     at processPromiseRejections (internal/process/promises.js:209:33)
6:03:56 PM:     at processTicksAndRejections (internal/process/task_queues.js:98:32)
6:03:56 PM: (Use `node --trace-uncaught ...` to show where the exception was thrown)

Hey @slim
Probably worth mentioning this as an issue on the official CLI repo as well.

Have you tried a clear cache and deploy - just a thought.
image

I did.

I’m assuming deployment builds are set as npm production! Is that not the case?

I’m sorry I don’t quite understand. Are you referring to production variables or dev deps?

dev deps. If npm is building production dev deps should NOT be being installed. That is not what I am seeing and I can find no documentation. I would have expected deploys to be production install / builds

As far as I’m aware tha’ts right, dev deps are dev deps for a reason.
Mind dropping your package.json?

I just removed netlify form the devDeps and it deploys !

{
    "scripts": {
    },
    "dependencies": {
        "uuid": "^8.3.2"
    }
}

this fails

{
    "scripts": {
    },
    "dependencies": {
        "uuid": "^8.3.2"
    },
    "devDependencies": {
        "netlify-cli": "^10.0.0"
    }
}

following instructions here Debugging with Visual Studio Code

1 Like

Okay that gives us some information to work with.

Digging around in the docs I found this:

If you set the NODE_ENV to production, any devDependencies in your package.json file will not be installed for the build.

Give this a go: Re-install netlify-cli and set a NODE_ENV in deploy settings.
Let me know how it pans out :slight_smile:

1 Like

Ah, for some reason I assumed that would be a default. Thanks!

No worries, guess we both learned something :slight_smile:

2 Likes

Thanks so much for sharing those insights @kylesloper! This thread will definitely be beneficial for additional Forums members who encounter something similar. Glad everything is working for you now, @slim :raised_hands:

3 Likes