Skip to content

Receiving 404 Module not found when importing js as type module  #3198

Closed
@codecycletechnologies

Description

@codecycletechnologies

Bug report

What is the current behavior?
Hi,
I am trying to integrate https://github.com/PolymerLabs/playground-elements with webpack.
For installing and using playground we need to add below code in index.html file.

<script
  type="module"
  src="/node_modules/playground-elements/playground-ide.js"
></script>

When we run this setup with webpack dev server, we are receiving 404 not found error for playground-ide.js

webpack.config.js

{
    mode: 'development',
    entry: { app: './index.ts' },
    devtool: 'inline-source-map',
    devServer: {
        contentBase: './dist',
    },
    watchOptions: {
        ignored: [ 'test/**', '**/node_modules' ],
    },
    resolve: {
        extensions: [ '.ts', '.js', '.html' ],
    },
    output: {
        path: resolve( './', 'dist' ),
        filename: '[name].js'
    },
    plugins: [
        new HtmlWebpackPlugin( {
            template: './src/index.html'
        } )
    ],
    module: {
        rules: [
            {
                test: /\.tsx?$/,
                use: 'ts-loader',
                exclude: /node_modules/,
            },
            {
                test: /\.m?js$/,
                exclude: /node_modules/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: [ '@babel/preset-env' ]
                    }
                }
            },
            {
                test: /\.(png|svg|jpg|gif)$/,
                use: [
                    'file-loader'
                ]
            },
            {
                test: /\.(woff|woff2|eot|ttf|otf)$/,
                use: [
                    'file-loader'
                ]
            }
        ],
    },
    optimization: {
        splitChunks: {
            chunks: 'all'
        }
    }
}

If the current behavior is a bug, please provide the steps to reproduce.
Steps to reproduce

  • use given web pack config
  • add playground-ide in index.html as type module
  • run web dev server and you will receive 404 not found

What is the expected behavior?

Other relevant information:
webpack version:
Node.js version:
Operating System:
Additional tools:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions