babel: Object is not a function error using v7.13.x

Bug Report

image

image

Current behavior

my package.json using babel v6,while some package like react-redux using babel ^7.1.1. babel v6 comile v7.13.x to image above,i think thatis the question

- Babel version(s): [package.json v6 ,error package v7.13.x]
- Node/npm version: [v12]
- OS: [macos]
- How you are using Babel: [`webpack`]

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 20 (9 by maintainers)

Most upvoted comments

@LeventLei This is a bug in af-webpack (a dependency of roadhog): it tells webpack “If an extension is not one of html|ejs|json|js|jsx|ts|tsx|css|less|scss|sass, load it as a string URL instead of executing it”. Webpack’s default behavior would be to load .mjs files as JavaScript, but af-webpack prevents it from doing so.

As a workaround, you can add urlLoaderExcludes: [/\.mjs$/, /\.cjs$/], to your .webpackrc.js config (I also added .cjs because it’s another JS extension that af-webpack doesn’t handle correctly, even if it’s not related to the current error), but I strongly suggest reporting this bug to af-webpack so that they can fix it.

I found it directly in the af-webpack source code 😄

thanks ,i solved this problem by adding mjs in webpack confg. { exclude: [ /.(js|jsx|mjs|html|json)$/], loader: ‘file-loader’, options: { name: config.mediaChunkFileName, }, }

why not use .js

@nicolo-ribaudo It really works for me , much appreciated

object-not-defined.zip this is my project simple,thanks @nicolo-ribaudo

I still can’t solve my problem, what else can I apply for your help @nicolo-ribaudo

why not use .js

Because:

  1. It has a different meaning in Node.js
  2. mjs supported by default in every bundler

The only problem is when you configure webpack to handle mjs files with a different loader (file-loader in your case).