Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Can't resolve '@babel/runtime/helpers/esm/extends [7.13.0 to 7.13.5] #12881

Closed
merlinstardust opened this issue Feb 23, 2021 · 41 comments · Fixed by #12883
Closed

bug: Can't resolve '@babel/runtime/helpers/esm/extends [7.13.0 to 7.13.5] #12881

merlinstardust opened this issue Feb 23, 2021 · 41 comments · Fixed by #12883
Labels
i: bug i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@merlinstardust
Copy link

Bug Report

Current behavior

When the Run server step runs in this GitHub Actions Build, this error is given:

ModuleNotFoundError: Module not found: Error: Can't resolve '@babel/runtime/helpers/esm/extends'

This currently happens with @babel/runtime from 7.13.0 to 7.13.5.

Current Fix
I was able to resolve this by install @babel/runtimeas a devDependency and forcing it to stay at7.12.18`. This can be seen in this GitHub Actions Build

Environment

  System:
    OS: macOS 10.15.7
  Binaries:
    Node: 12.20.1 - ~/.nvm/versions/node/v12.20.1/bin/node
    npm: 6.14.10 - ~/.nvm/versions/node/v12.20.1/bin/npm
  npmPackages:
    @babel/register: ^7.10.4 => 7.12.13 
    babel-eslint: ^10.0.1 => 10.1.0 
    babel-jest: ^25.1.0 => 25.5.1 
    babel-plugin-module-resolver: ^4.0.0 => 4.1.0 
    eslint: ^6.8.0 => 6.8.0 
    eslint-import-resolver-babel-module: ^5.1.2 => 5.2.0 
    jest: ^26.1.0 => 26.6.3 
    webpack: ^4.32.0 => 4.46.0 

Additional context
I'm not sure but I think this may be related to #12880.

@babel-bot
Copy link
Collaborator

Hey @merlinpatt! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite."

@nicolo-ribaudo
Copy link
Member

This might be fixed by #12877

@nicolo-ribaudo
Copy link
Member

Can you check if v7.13.6 of @babel/runtime fixes this?

@merlinstardust
Copy link
Author

Unfortunately it did not fix it.

@akshay-kr
Copy link

I am also facing the same issue. Updating @babel/runtime version to v7.13.6 did not work but forcing to stay on 7.12.18 fixed the issue.

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Feb 23, 2021

In @babel/runtime/helpers/extends there is an index.js file, so I'm not sure how something could not resolve it 🤔

https://unpkg.com/browse/@babel/runtime@7.13.6/helpers/extends/

@nicolo-ribaudo
Copy link
Member

Oh I think I know the problem

@nicolo-ribaudo
Copy link
Member

I accidentally pushed the fix to main rather than to a PR: cfdbdc0

The problem is that we had export maps like "./helpers/esm/*: "./helpers/esm/*.js" which don't work in every tool, so we also had "./helpers/esm/: "./helpers/esm/" as a fallback.
However, the fallback doesn't specify the .js extension, so it fails in some tools.

I fixed it by explicitly listing all the exports of the esm folder.

@fengxinming
Copy link

.mjs may not be resolved in some reasons,please @nicolo-ribaudo change _index.mjs to _index.js

@nicolo-ribaudo
Copy link
Member

Sorry I forgot to release the fix, doing it now: https://github.com/babel/babel/actions/runs/595458532

@tianleiwufeng
Copy link

tianleiwufeng commented Feb 24, 2021

image

the error is:Object(...) is not a function
i face the same question with v7.13.7,my outer babel version is v6,while some package use v7

@nicolo-ribaudo
Copy link
Member

That seems unrelated, please open a new issue with a link to a GitHub repository I can download to reproduce the error.

@beiifeng
Copy link

That seems unrelated, please open a new issue with a link to a GitHub repository I can download to reproduce the error.

image

image

@nicolo-ribaudo
Copy link
Member

please open a new issue with a link to a GitHub repository I can download to reproduce the error.

This is the important part: without it I don't know what's the issue.

From the first screenshot you posted it seems like that file is exporting a string, but it's clearly not exporting a string in the second screenshot.

@tianleiwufeng
Copy link

i guess babel v6 compile v7.13.x into
image

@beiifeng
Copy link

please open a new issue with a link to a GitHub repository I can download to reproduce the error.

This is the important part: without it I don't know what's the issue.

From the first screenshot you posted it seems like that file is exporting a string, but it's clearly not exporting a string in the second screenshot.

first screenshot:
we think it will import an function from "@babel/runtime/helpers/esm/slicedToArray" , but got an file content with base64.

second screenshot:
if i change _export { default } from "../slicedToArray/index.mjs" to export { default } from "../slicedToArray/index.js" , it will be ok.

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Feb 24, 2021

I see, but why is it loading that file as base64? That doesn't make sense in any runtime or bundler I know of.

index.mjs is a normal JavaScript esm file.

@beiifeng
Copy link

I see, but why is it loading that file as base64? That doesn't make sense in any runtime or bundler I know of.

index.mjs is a normal JavaScript esm file.

yeah, maybe wrong config/env... or old version of webpack.

@beiifeng
Copy link

i will making repository with sample for reproduce .

@quicksand-1
Copy link

That seems unrelated, please open a new issue with a link to a GitHub repository I can download to reproduce the error.

image

image

the project package.json add @Babel/core, @Babel/runtime, @Babel/runtime-corejs3 is 7.12.X. The problem of error reporting has been solved temporarily

@nicolo-ribaudo
Copy link
Member

Could it be facebook/create-react-app#5234? It seems like a create-react-app bug.

@beiifeng
Copy link

beiifeng commented Feb 24, 2021

resolved.

why is it loading that file as base64 : url-loader. It build-in roadhog.

solution:
add webpack.config.js as

module.exports = config => {
  config.module.rules.forEach(item => {
    if (item.loader && item.loader.indexOf('url-loader') > -1) {
      item.exclude.push(/\.mjs$/);
    }
  });
  return config;
};

thanks

@paulashwin
Copy link

We are getting this below error after upgrading babel from 7.12.x to 7.13.x. Any idea to resolve would be of much help.

Uncaught Error: Could not find module `@babel/runtime/helpers/defineProperty/_index.mjs` imported from `@babel/runtime/helpers/esm/defineProperty`
    at missingModule (loader.js:247)
    at findModule (loader.js:258)
    at Module.findDeps (loader.js:168)
    at findModule (loader.js:262)
    at Module.findDeps (loader.js:168)
    at findModule (loader.js:262)
    at Module.findDeps (loader.js:168)
    at findModule (loader.js:262)
    at requireModule (loader.js:24)
    at tests-suffix.js:1

@nicolo-ribaudo
Copy link
Member

@paulashwin If the @babel/runtime/helpers/esm/defineProperty.js file looks like this: https://unpkg.com/browse/@babel/runtime@7.13.7/helpers/esm/defineProperty.js
and if @babel/runtime/helpers/defineProperty/_index.mjs exists, then it's a bug in whatever tool/bundler is throwing that error 🤔

@nicolo-ribaudo
Copy link
Member

I'm closing this issue, since:

  1. The original bug report has been fixed.
  2. @beiifeng fixed the webpack config problem (which is caused by a roadhog or af-webpack bug, where it loads some JS files as URLs)
  3. @tianleiwufeng solved the problem (Object is not a function error using v7.13.x #12888 (comment)), which was again caused by a wrong webpack config that transformed .mjs files to strings rather than handling them as js
  4. @paulashwin's error is completely different. Please open a new issue with a repository I can clone to reproduce the bug.

@paztis
Copy link

paztis commented Feb 24, 2021

freshly installed @babel/runtime v7.13.7
I crash my typescript builds (4.2.2)

it is due to
helpers/extends/index.js badly generated code
seems there's inner module.exports in the function declaration

function _extends() {
  module.exports = _extends = Object.assign || function (target) {
    for (var i = 1; i < arguments.length; i++) {
      var source = arguments[i];

      for (var key in source) {
        if (Object.prototype.hasOwnProperty.call(source, key)) {
          target[key] = source[key];
        }
      }
    }

    return target;
  };

  module.exports["default"] = module.exports, module.exports.__esModule = true;
  return _extends.apply(this, arguments);
}

module.exports = _extends;
module.exports["default"] = module.exports, module.exports.__esModule = true;

works correctly when I change the content of index.js file with the content of _index.mjs

export default function _extends() {
  _extends = Object.assign || function (target) {
    for (var i = 1; i < arguments.length; i++) {
      var source = arguments[i];

      for (var key in source) {
        if (Object.prototype.hasOwnProperty.call(source, key)) {
          target[key] = source[key];
        }
      }
    }

    return target;
  };

  return _extends.apply(this, arguments);
}

@nicolo-ribaudo
Copy link
Member

@paztis What bundler are you using?

@paztis
Copy link

paztis commented Feb 24, 2021

typescript (tsc)
But here it is parsing a javascript file that be transpiled with babel (class extends transpilation) .

It was not failing until I upgrade to babel 7.13. Any changes on your side in the source code of this file ?

@nicolo-ribaudo
Copy link
Member

Any changes on your side in the source code of this file?

This file is new, the previous versions were https://unpkg.com/browse/@babel/runtime@7.12.0/helpers/extends.js and https://unpkg.com/browse/@babel/runtime@7.12.0/helpers/esm/extends.js. I think #12883 will fix your error, but I cannot be sure without knowing what is throwing the error (Node.js? Webpack? another bundler? tsc itself when typechecking?)

@paztis
Copy link

paztis commented Feb 24, 2021 via email

@JLHwung
Copy link
Contributor

JLHwung commented Feb 24, 2021

Can you provide a reproduction repo?

@paztis
Copy link

paztis commented Feb 24, 2021

Hard for me. We've got a n enormous private repo that was working fine and sudently crashes.
Here is the ts config file:

{
  "compilerOptions": {
    "jsx": "react-jsx"
    "target": "esnext",
    "module": "esnext",
    "moduleResolution": "node",
    // Process & infer types from .js files.
    "allowJs": true,
    "maxNodeModuleJsDepth": 3,
    // Enable strictest settings like strictNullChecks & noImplicitAny.
    "strict": false,
    "noImplicitAny": true,
    "noImplicitReturns": true,
    // "noImplicitThis": true,
    "isolatedModules": false, // Disallow features that require cross-file information for emit.
    "esModuleInterop": true, // Import non-ES modules as default imports.
    "skipLibCheck": true, // Do not validate the dependencies definitions
    "experimentalDecorators": true,
    "suppressImplicitAnyIndexErrors": true,
    // resolution of dependencies/
    "resolveJsonModule": true,
    "baseUrl": "."
  }
}

With allowJs option it processes the us files also.
Typescript version is 4.2.2

@paztis
Copy link

paztis commented Feb 24, 2021

I also create a defect in typescript: microsoft/TypeScript#42942 (comment)

@paztis
Copy link

paztis commented Feb 24, 2021

here is a repo where I reproduce the defect
https://codesandbox.io/s/twilight-sound-ll66d?file=/tsconfig.json

Locally, with the same code I've the error, but don't know why not on codeSandbox

just run the command npm run build on it

extra info: node: v14.15.0, system: bigSur

@paztis
Copy link

paztis commented Feb 24, 2021

no I create from scratch specific repo and always reproduce it
Try toi create also the same repo locally and you will see

It contains only 4 files: package.json, tsConfig.json, src/index.ts and src/js/problematicFile.js
Do npm install (or yarn install), then npm run build

@nicolo-ribaudo
Copy link
Member

It's possible that this will be fixed by 6a471de in the next release, but I'm not 100% sure because I cannot reproduce the error when I download that codesandbox example ☹️

@paztis
Copy link

paztis commented Feb 24, 2021

ok I've update the codeSandbox: https://codesandbox.io/s/twilight-sound-ll66d
I was setting index.js instead of index.ts

you can test in now it fails everywhere

when will be the next release ?
any way to test it ?

@nicolo-ribaudo
Copy link
Member

Ok, I can reproduce the error. However, I now understand that it will not be fixed in the next Babel release because this is 100% a TypeScript bug.

@hoIIer
Copy link

hoIIer commented Feb 28, 2021

just hit this in my project using ember-cli-babel@7.24.0 that uses @babel/runtime: ^7.12.0 and resolves to 7.13.X

Error: Could not find module `@babel/runtime/helpers/initializerDefineProperty/_index.mjs` imported from `@babel/runtime/helpers/esm/initializerDefineProperty`

@nicolo-ribaudo
Copy link
Member

@burritoIand That isn't a Babel bug. Whatever bundler Ember is using, it probably configured to ignore files ending in mjs.

However, we might stop using .mjs to workaround this bundler/configuration bug: #12919

@hoIIer
Copy link

hoIIer commented Mar 1, 2021

@burritoIand That isn't a Babel bug. Whatever bundler Ember is using, it probably configured to ignore files ending in mjs.

However, we might stop using .mjs to workaround this bundler/configuration bug: #12919

@nicolo-ribaudo ok great thanks!

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jun 1, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: bug i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.