question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple assets emit different content to the same filename ../main.js.nft.json

See original GitHub issue

We are trying to migrate from a CRA-based React app to NextJS by importing the root component directly in the Next build. Our plan is to get Next building our bundles, and then we can migrate the pages out one by one without having to do everything at once.

The project uses npm workspaces.

// new-app/pages/index.tsx
import RootComponent from '@watershed/app/src/admin/AdminRoot';

function HomePage() {
  return <RootComponent />;
}

export default HomePage;

When we run next build we get an unexpected error without enough context to resolve:


> @watershed/app-admin@0.1.0 build
> next build

info  - Checking validity of types
info  - Creating an optimized production build
Failed to compile.

Conflict: Multiple assets emit different content to the same filename ../main.js.nft.json

> Build failed because of webpack errors
npm ERR! Lifecycle script `build` failed with error:
npm ERR! Error: command failed
npm ERR!   in workspace: @watershed/app-admin@0.1.0
npm ERR!   at location: /Users/adamrneary/github/ghg/client/workspaces/app-admin

What would be the best way to diagnose this? Is this something folks have seen before? Happy to collaborate on a fix, but I am not sure where to start. Thanks in advance for your time!

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
adamrnearycommented, Jan 13, 2022

@ivantm I appreciate that (in earnest), but we’re trying to get this working with Next 12.

1reaction
medihackcommented, Apr 7, 2022

@shifengdiy I have it working with an up-to-date NextJS 12. Below is the relevant code. It uses some custom language service, but it’ll hopefully give you the idea…

// next.config.js
/** @type {import('next').NextConfig} */
const MonacoWebpackPlugin = require("monaco-editor-webpack-plugin");
const path = require("path");

const nextConfig = {
  reactStrictMode: true,
  webpack: (config, options) => {
    // Allows to load CSS in monaco-editor as Next.js does not handle CSS in
    // node modules folder.
    // Workaround until RFC is through: https://github.com/vercel/next.js/discussions/27953
    config.module.rules
      .find((rule) => rule.oneOf)
      .oneOf.forEach((r) => {
        if (r.issuer?.and?.[0]?.toString().includes("_app")) {
          r.issuer = [
            { and: r.issuer.and },
            /[\\/]node_modules[\\/]monaco-editor[\\/]/,
          ];
        }
      });

    // See https://github.com/vercel/next.js/issues/31692#issuecomment-1061260424
    if (!options.isServer) {
      config.plugins.push(
        new MonacoWebpackPlugin({
          languages: [],
          filename: "static/[name].js",
          customLanguages: [
            {
              label: "medtl",
              worker: {
                id: "vs/language/medtl/medtlWorker",
                entry: path.resolve(
                  "./node_modules/@medtl/monaco-plugin/dist/medtl.worker.js"
                ),
              },
            },
          ],
        })
      );
    }
    return config;
  },
};

module.exports = nextConfig;
// pages/editor.tsx
import { NextPage } from "next";
import dynamic from "next/dynamic";

const MedtlEditor = dynamic(() => import("../src/components/MedtlEditor"), {
  ssr: false,
});

const Editor: NextPage = () => {
  return (
    <div>
      <MedtlEditor />
    </div>
  );
};

export default Editor;
// src/components/MedtlEditor.tsx
import MonacoEditor from "react-monaco-editor";
import { setDiagnosticsOptions } from "@medtl/monaco-plugin";

const MedtlEditor = () => {
  return (
    <div>
      <MonacoEditor
        width={800}
        height={600}
        language="medtl"
        editorDidMount={() => {
          setDiagnosticsOptions();
          console.log("Editor ready");
        }}
      />
    </div>
  );
};

export default MedtlEditor;

Hope this helps.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Conflict: Multiple assets emit to the same filename
what I want to know is what tool writes an error like "Conflict: Multiple assets emit to the same filename slots.js". Why would...
Read more >
JavaScript : Conflict: Multiple assets emit to the same filename
JavaScript : Conflict: Multiple assets emit to the same filename [ Gift : Animated Search Engine : https://bit.ly/AnimSearch ] JavaScript ...
Read more >
Multiple assets emit different content to the same filename ...
js in src\assets\metronic\vendors\global,@fortawesome so that the app will reference the files in \node_modules@fortawesome?
Read more >
Multiple assets emit to the same filename bundle.js - Laracasts
I can get the most basic tests running with just a webpack config file to use vue-loader on .vue files, but as soon...
Read more >
Advanced Features: Output File Tracing - Next.js
json files emitted to the .next output directory, you can read the list of files in each trace that are relative to the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found