Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

Unresolved dependencies core-js #313

Closed
bosens-China opened this issue Jul 8, 2019 · 11 comments
Closed

Unresolved dependencies core-js #313

bosens-China opened this issue Jul 8, 2019 · 11 comments

Comments

@bosens-China
Copy link

Output information

https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency
core-js/modules/es.array.from (imported by src\i.js)
core-js/modules/es.string.iterator (imported by src\i.js)

expect

Packing Dependencies Correctly into Output Files

configure

babel.config.js

module.exports = {
  presets: [
    [
      '@babel/preset-env',
      {
        useBuiltIns: 'usage',
        // useBuiltIns: 'entry',
        corejs: 3,
        modules: false,
      },
    ],
    ['@babel/preset-typescript'],
  ],
  plugins: [
    '@babel/plugin-transform-typescript',
    '@babel/plugin-syntax-dynamic-import',
    '@babel/plugin-proposal-class-properties',
  ],
};

rollup.config.js

import babel from 'rollup-plugin-babel';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import { terser } from 'rollup-plugin-terser';
export default {
  input: './src/index.ts',
  output: [
    {
      file: 'dist/index.esm.js',
      format: 'cjs',
      sourcemap: true,
    },
    {
      file: 'dist/index.js',
      format: 'umd',
      sourcemap: true,
      name: 'lazyLoad',
    },
    {
      file: 'dist/index.esm.browser.js',
      format: 'es',
      sourcemap: true,
    },
  ],
  plugins: [
    resolve(),
    commonjs(),
    // terser(),
    babel({
      extensions: ['js', 'ts'],
    })
  ],
};

I think it's the Babel 7 useBuiltIns problem, but what should I do?

@loganfsmyth
Copy link
Collaborator

You need to add core-js as a dependency if you are using useBuiltIns: 'usage'. https://babeljs.io/docs/en/babel-preset-env#usebuiltins

This option adds direct references to the core-js module as bare imports. Thus core-js will be resolved relative to the file itself and needs to be accessible. You may need to specify core-js@2 as a top level dependency in your application if there isn't a core-js dependency or there are multiple versions.

@bosens-China
Copy link
Author

@loganfsmyth
You're right. I looked up the dependencies and found that corejs was installed.

@drzraf
Copy link

drzraf commented Aug 13, 2019

@loganfsmyth: What do you mean exactly by add core-js as a dependency?

@loganfsmyth
Copy link
Collaborator

@drzraf Add it in your package.json's dependencies.

@northkode
Copy link

adding as a dependency still doesnt fix the unresolved dependencies for all the runtime helpers

@g-zachar
Copy link

Is there any followup to this? I'm also experiencing this issue.

@mcarlucci
Copy link

+1

@nicolo-ribaudo
Copy link
Contributor

Which file is requiring core-js?

@Donnevtis
Copy link

I'd solved this problem by adding 'exclude' option for babel-plugin.
exclude: 'node_modules/core-js/**',
Attention: for yarn or pnpm could be need another path.
Babel shouldn't transpilling core-js code.

sounisi5011 added a commit to sounisi5011/sounisi5011.jp that referenced this issue Feb 27, 2020
「Circular dependency」警告の発生と実行不可能なスクリプトが生成される問題でかなり手こずったものの、解決に成功した。
なぜこれで上手くいくのかよく解っていないが、excludeオプションは必須。

参考:

* rollup/rollup-plugin-babel#254
* rollup/rollup-plugin-babel#313 (comment)
* https://github.com/rollup/rollup-plugin-babel/blob/a5489208c33dd99f71a3f30b228fd02d18008b5f/README.md#external-dependencies
@nerdess
Copy link

nerdess commented Mar 29, 2020

i am also getting the circular dependencies error even though i've excluded core-js from babel. my babel config inside rollup.config.js:

		babel({
			extensions: [ '.js', '.mjs', '.html', '.svelte' ],
			runtimeHelpers: true,
			exclude: [ 'node_modules/@babel/**', 'node_modules/core-js/**' ],
			presets: [
			  [
				'@babel/preset-env',
				{
					targets: '> 0.25%, not dead',
					useBuiltIns: 'usage',
					corejs: 3
				}
			  ]
			],
			plugins: [
			  '@babel/plugin-syntax-dynamic-import',
			  [
				'@babel/plugin-transform-runtime',
				{
				  useESModules: true
				}
			  ]
			]
		  }),	

any more hints/ideas?

@nerdess
Copy link

nerdess commented Mar 29, 2020

ah sorry fixed, forgot to add "core-js": "^3.6.4" as a dependency inside package.json

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants