twopluszero / next-images

Import images in Next.js (supports jpg, jpeg, svg, png and gif images)
MIT License
949 stars 67 forks source link

assetPrefix is undefined #20

Closed MrRhodes closed 4 years ago

MrRhodes commented 5 years ago

I've just encountered an issue were assetPrefix was undefined and was setting my image assets to be undefined/_next/static...

I believe it is on this line when creating the new nextConfig https://github.com/twopluszero/next-images/blob/73b49921e870d4f1e75c32bf7d7c3269375af51b/index.js#L5

if nextConfig already has assetPrefix set as undefined it does not default to "" and then causes this to created as a string...

In my config i have the following:

     assetPrefix: process.env.PUBLIC_URL,

...which is only set when I am deploying to prod, for local dev this env variable is... undefined

I'll expand on this later, i just wanted to log this issue now as I've resolved it for myself by defaulting in my config..

     assetPrefix: process.env.PUBLIC_URL || '',