Hi all I am trying to write a Netlify plugin for my svelte-kit app following this blog post: How to Contextualize your env vars with Netlify Build Plugins
Netlify specifically looks for an index.js
for their plugins as shown in this subreddit answer:
When we create a brand new svelte-kit app, the package.json
has type: module
specified. Because of that, running netlify build
to try the build locally fails because:
Could not import plugin:
ReferenceError: module is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/Users/website/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
But, if I change the extension to .cjs
, Netlify doesnβt find the plugin as it looks specifically for index.js
as mentioned before.
Has anyone had this problem? And how have you dealt with it?
I have pushed a demo version of my problem in this repo:
Thanks for your help!