nandorojo / solito

🧍‍♂️ React Native + Next.js, unified.
https://solito.dev
MIT License
3.54k stars 181 forks source link

Static images in Expo + Next #78

Closed RichardLindhout closed 2 years ago

RichardLindhout commented 2 years ago

Images are not loaded now in Next.js, I did put my images at packages/app/assets. On NextJS it renders an empty view without any image ta Schermafbeelding 2022-06-02 om 23 09 35 g

nandorojo commented 2 years ago

try adding next-images to your next config

nandorojo commented 2 years ago

any luck?

RichardLindhout commented 2 years ago

Did not see your comment yet. @arjendevos can you try this tomorrow, see instructions here: https://www.npmjs.com/package/next-images

arjendevos commented 2 years ago

@RichardLindhout It appears to break when i add next-images to the next.config file. TypeError: unsupported file type: undefined (file: undefined)

louisholley commented 2 years ago

@arjendevos i fixed this issue by passing:

[
      withImages,
      {
        exclude: path.resolve(__dirname, "../../node_modules/*"),
        images: {
          disableStaticImages: true,
        },
      },
    ],

to withPlugins

nandorojo commented 2 years ago

In general, would be useful for you guys to share full code (ie your entire next config file). It's hard to debug without that.

@louisholley thanks for sharing that

MainStreetTech commented 2 years ago

@louisholley, that'd be great if you could share the before and after next.config file

louisholley commented 2 years ago

@MainStreetTech before:

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  webpack5: true,
};

const { withExpo } = require("@expo/next-adapter");
const withPlugins = require("next-compose-plugins");
const withFonts = require("next-fonts");
const withTM = require("next-transpile-modules")([
  "solito",
  "dripsy",
  "@dripsy/core",
  "@dripsy/gradient",
  "moti",
  "@motify/core",
  "@motify/components",
  "app",
  "react-native-web",
  "react-native-svg",
  "native-base",
]);

module.exports = withPlugins(
  [withTM, withFonts, [withExpo, { projectRoot: __dirname }]],
  nextConfig
);

after:

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  webpack5: true,
};

const path = require("path");
const { withExpo } = require("@expo/next-adapter");
const withPlugins = require("next-compose-plugins");
const withFonts = require("next-fonts");
const withImages = require("next-images");
const withTM = require("next-transpile-modules")([
  "solito",
  "dripsy",
  "@dripsy/core",
  "@dripsy/gradient",
  "moti",
  "@motify/core",
  "@motify/components",
  "app",
  "react-native-web",
  "react-native-svg",
  "native-base",
]);

module.exports = withPlugins(
  [
    withTM,
    withFonts,
    [
      withImages,
      {
        exclude: path.resolve(__dirname, "../../node_modules/*"),
        images: {
          disableStaticImages: true,
        },
      },
    ],
    [withExpo, { projectRoot: __dirname }],
  ],
  nextConfig
);
nandorojo commented 2 years ago

I have something similar, except I don’t use exclude. I also put the images object directly into nextConfig

I’ll see what I have to the solito starter when I have some time

MainStreetTech commented 2 years ago

@nandorojo @louisholley Thank you

This is working for me now

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  webpack5: true,
}

const { withExpo } = require('@expo/next-adapter')
const withPlugins = require('next-compose-plugins')
const withImages = require('next-images')
const withTM = require('next-transpile-modules')([
  'solito',
  'dripsy',
  '@dripsy/core',
  'moti',
  '@motify/core',
  '@motify/components',
  'app',
])

module.exports = withPlugins(
  [withTM, [
    withImages,
    {
      images: {
        disableStaticImages: true,
      },
    },
  ],[withExpo, { projectRoot: __dirname }]],
  nextConfig
)
nandorojo commented 2 years ago

Hey guys, try out the new solito/image: https://solito.dev/usage/image

It doesn't support optimizations via require, only import. Once all images use import instead of require, you can remove disableStaticImages: true from your next config.