next-remove-imports icon indicating copy to clipboard operation
next-remove-imports copied to clipboard

Usage with mjs configs

Open RobotSail opened this issue 2 years ago • 6 comments

Hi all, I'm running into difficulty with using next-remove-imports in a project which uses next.config.mjs instead of the standard next.config.js, which is currently documented. Any guidance on how to proceed here?

My config currently looks like this:

// @ts-check

import removeImports from 'next-remove-imports'

/**
 * Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation.
 * This is especially useful for Docker builds.
 */
!process.env.SKIP_ENV_VALIDATION && (await import("./src/env.mjs"));


/** @type {import("next").NextConfig} */
const config = {
  reactStrictMode: true,

  /**
   * If you have the "experimental: { appDir: true }" setting enabled, then you
   * must comment the below `i18n` config out.
   *
   * @see https://github.com/vercel/next.js/issues/41980
   */
  i18n: {
    locales: ["en"],
    defaultLocale: "en",
  },
  ...removeImports(),
};
export default config;

RobotSail avatar Feb 20 '23 14:02 RobotSail

I've described the problem in this issue, but the problem seems to be that the TypeScript signature of removeImports doesn't allow me to provide my existing config, and merging the result of removeImports() doesn't seem to have any effect.

RobotSail avatar Feb 20 '23 14:02 RobotSail

@RobotSail

https://github.com/uiwjs/next-remove-imports/blob/0e23be8ea25012e3131217a285586583dbf5ff36/core/src/index.ts#L8

import removeImports from 'next-remove-imports'

const removeImportsFun = removeImports({
  options: { },
})

export default removeImportsFun({
  reactStrictMode: true,
  i18n: {
    locales: ["en"],
    defaultLocale: "en",
  },
})

jaywcjlove avatar Feb 21 '23 01:02 jaywcjlove

https://github.com/uiwjs/next-remove-imports/blob/e90b3441c8d2d519271eb1be1cab5f999f92848b/example/esm/next.config.mjs#L1-L16

jaywcjlove avatar Feb 21 '23 02:02 jaywcjlove

Thanks @jaywcjlove!

RobotSail avatar Feb 21 '23 12:02 RobotSail

I'm using this package exatcly as described in readme, but unable to import scss at component level still

ticmaisdev avatar May 13 '23 23:05 ticmaisdev

@ticmaidev https://github.com/uiwjs/next-remove-imports/tree/main/example

You can provide a reproducible example through codesandbox.io, and I'll help you take a look.

jaywcjlove avatar May 14 '23 05:05 jaywcjlove