Upgraded to Webpack 5 and now it outputs to dist/main.js, which isn't a thing. Anyone know how to handle this?

Hi all,

Been on this for hours now and Webpack isn’t behaving as I would assume. Has anyone had Webpack create a dist/main.js because it thinks it doesn’t have enough information (like entry) and so it still builds correctly, but also spits out a dist/main.js?

I posted the question on Stackoverflow here:

Any ideas/suggestions would be greatly appreciated. :pray:

I’ll post the question here too as well:


I am using Webpack with Elixir/Phoenix. I recently upgraded to Webpack 5 from Webpack 4.

I think everything is working fine except that now for some reason a dist and main.js are always created at the project root dist/main.js when I run my tests. This file is mostly empty:

/*
 * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
 * This devtool is neither made for production nor for readable output files.
 * It uses "eval()" calls to create a separate source file in the browser devtools.
 * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
 * or disable the default devtool with "devtool: false".
 * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
 */
/******/ (() => { // webpackBootstrap
/******/ 	"use strict";
/******/ 	
/******/ 	
/******/ })()
;

In my mix.exs I have the following. This is the line of code that creates the dist/main.js

  defp compile_assets(_) do
    Mix.shell().cmd("./assets/node_modules/webpack/bin/webpack.js --mode development",
      quiet: false
    )
  en

My webpack.config includes:

    devtool: 'eval-source-map',
    entry: {
      'app': glob.sync('./vendor/**/*.js').concat(['./js/app.js']),
      'marketing': glob.sync('./vendor/**/*.js').concat(['./js/marketing.js']),
      'admin': glob.sync('./vendor/**/*.js').concat(['./js/admin.js']),
    },
    output: {
      filename: '[name].js',
      path: path.resolve(__dirname, '../priv/static/js')
    },

When I run this in IEx I get:

iex(1)> Mix.shell().cmd("./assets/node_modules/webpack/bin/webpack.js --mode development", quiet: false)
asset main.js 662 bytes [emitted] (name: main)

ERROR in main
Module not found: Error: Can't resolve './src' in '/Users/me/development/apps/my_app'
resolve './src' in '/Users/me/development/apps/my_app'
  No description file found in /Users/me/development/apps/my_app or above
  No description file found in /Users/me/development/apps/my_app or above
  no extension
    /Users/me/development/apps/my_app/src doesn't exist
  .js
    /Users/me/development/apps/my_app/src.js doesn't exist
  .json
    /Users/me/development/apps/my_app/src.json doesn't exist
  .wasm
    /Users/me/development/apps/my_app/src.wasm doesn't exist
  as directory
    /Users/me/development/apps/my_app/src doesn't exist

webpack 5.50.0 compiled with 1 error in 50 ms
1

Since I have specified the entry I would assume it should be fine. Any help would be greatly appreciated.

1 Like

Whenever something involves node or npm, my usual solution is to sit down and cry for a while. Your mileage may vary with that though.

Edit: I have no recommendations whatsoever regarding webpack, but phoenix 1.6 will be moving to esbuild. Here are a few links about it and dart_sass:

7 Likes

Hello, brother? :039: :044:

3 Likes

I got it!

It turns out I had used a setup from Wallaby that was no longer current.

Here is the change I missed:

Does anyone know a way to keep up with changes like these that don’t get much visibility? (Not just for Wallaby but for all libraries)