plugins icon indicating copy to clipboard operation
plugins copied to clipboard

commonjs - Missing export (Error: ... is not exported by ...)

Open danielgindi opened this issue 3 years ago • 23 comments

  • Rollup Plugin Name: commonjs
  • Rollup Plugin Version: 20.0.0
  • Rollup Version: 2.56.3
  • Operating System (or Browser): macOS
  • Node Version: 16
  • Link to reproduction (⚠️ read below): https://replit.com/@danielcgindi/rollup-plugin-repro-4

Expected Behavior

Should correctly export whatever is imported.

Actual Behavior

Weird and irrelevant export.

The piece of code (importDeclaration.module.info.code) that fails looks like this:

import * as commonjsHelpers from "

danielgindi avatar Sep 01 '21 20:09 danielgindi

Seems to be resolved by #1038

lukastaegert avatar Nov 26 '21 05:11 lukastaegert

There still seems to be the or at least a bug.

In Short: I am importing a lib that depends on axios/axios.

After updating to a version > 18 the import failed with

The requested module ... does not provide an export named 'exports'

as mentioned here and in the related post here: #modernweb-dev/web#1700.

Following the discussion(s) in #1038 and updating to v20.0.4 (beta), I get the following (new) error, though:

Error while transforming ... Could not resolve import "commonjsHelpers.js"

1 | import * as commonjsHelpers from "commonjsHelpers.js";
2 | import require$$0 from...

phihu avatar Jan 11 '22 16:01 phihu

I'm in the same boat as @phihu - any advice or direction here would be much appreciated :)

emensch avatar Feb 08 '22 23:02 emensch

Anyone any success? Problem still exists, even using the latest (beta) release v22.0.0-13

phihu avatar Mar 03 '22 14:03 phihu

v22.0.0 release and problem still exists

try transforming to commonjs the deepmerge npm module

mihaisavezi avatar Apr 27 '22 07:04 mihaisavezi

I also am getting the same kind of error message with version 22.0.0 when trying to process @testing-library/dom:

Error while transforming node_modules/@testing-library/dom/dist/helpers.js: Could not resolve import "commonjsHelpers.js".
> 1 | import * as commonjsHelpers from "commonjsHelpers.js";
    |                                  ^
  2 | import { __exports as helpers } from "\u0000/[redacted]/node_modules/@testing-library/dom/dist/helpers.js?commonjs-exports"
  3 |
  4 | "use strict";

b-houghton avatar Jun 06 '22 21:06 b-houghton

For anyone stuck at this problem: downgrading @rollup/plugin-commonjs to v21 solves for me.

songkeys avatar Jun 14 '22 11:06 songkeys

I'm having the same issue using vitejs when importing photoswipe.

jimblue avatar Jul 18 '22 19:07 jimblue

For anyone stuck at this problem: downgrading @rollup/plugin-commonjs to v21 solves for me. It works for me. thx!

Ssis53 avatar Aug 22 '22 09:08 Ssis53

If anyone finds any additional solutions, please update the thread! I'm also facing the same issue and downgrading hasn't helped either.

mhogara avatar Aug 25 '22 20:08 mhogara

Also having issues with this. Using via web-test-runner. Downgrading to v21 just freezes web-test-runner, while latest release errors with Could not resolve import "commonjsHelpers.js".

enjikaka avatar Aug 31 '22 12:08 enjikaka

I'm also having the same problem. v22 gives me the error about commonjsHelpers.js while v21 causes wtr to hang and eventually crash due to running out of memory. This is on a hello-world demo with a single test just to try to get wtr working.

jcoglan avatar Sep 21 '22 10:09 jcoglan

Same issue here with web-dev-server. v22 has the mentioned error and v21.1.0 just hangs:

<--- Last few GCs --->

[8057:0x604c890] 384504 ms: Mark-sweep 2008.1 (2082.1) -> 1995.8 (2082.8) MB, 2674.3 / 0.0 ms (average mu = 0.178, current mu = 0.071) task scavenge might not succeed [8057:0x604c890] 386388 ms: Mark-sweep 2009.2 (2082.8) -> 1996.6 (2083.6) MB, 1741.4 / 0.0 ms (average mu = 0.136, current mu = 0.076) task scavenge might not succeed [8057:0x604c890] 388341 ms: Mark-sweep 2010.1 (2083.8) -> 1997.4 (2084.6) MB, 1736.1 / 0.0 ms (average mu = 0.125, current mu = 0.111) task scavenge might not succeed

<--- JS stacktrace --->

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory 1: 0xb09c10 node::Abort() [node] 2: 0xa1c193 node::FatalError(char const*, char const*) [node] 3: 0xcf8dde v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node] 4: 0xcf9157 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node] 5: 0xeb09f5 [node] 6: 0xeb14d6 [node] 7: 0xebf9fe [node] 8: 0xec0440 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node] 9: 0xf23884 v8::internal::ScavengeJob::Task::RunInternal() [node] 10: 0xdb6f6b non-virtual thunk to v8::internal::CancelableTask::Run() [node] 11: 0xb77a54 node::PerIsolatePlatformData::RunForegroundTask(std::unique_ptr<v8::Task, std::default_deletev8::Task >) [node] 12: 0xb798b9 node::PerIsolatePlatformData::FlushForegroundTasksInternal() [node] 13: 0x1564956 [node] 14: 0x1577084 [node] 15: 0x15652a8 uv_run [node] 16: 0xa43dd5 node::SpinEventLoop(node::Environment*) [node] 17: 0xb4bdb6 node::NodeMainInstance::Run(node::EnvSerializeInfo const*) [node] 18: 0xacd592 node::Start(int, char**) [node] 19: 0x7b8494a8fd0a __libc_start_main [/lib/x86_64-linux-gnu/libc.so.6] 20: 0xa4067c [node] Aborted (core dumped)

trixter13 avatar Sep 21 '22 22:09 trixter13

Same issue here with vitejs : I tried with @rollup/plugin-commonjs@20, @rollup/plugin-commonjs@21, @rollup/plugin-commonjs@latest (23) with the same result..

Error when using sourcemap for reporting an error: Can't resolve original location of error.
'getDefaultExportFromCjs' is not exported by 'commonjsHelpers.js'
'commonjsGlobal' is not exported by 'commonjsHelpers.js'
(...)
'commonjsGlobal' is not exported by 'commonjsHelpers.js'
Error when using sourcemap for reporting an error: Can't resolve original location of error.
'getDefaultExportFromCjs' is not exported by 'commonjsHelpers.js'
'commonjsGlobal' is not exported by 'commonjsHelpers.js'
✓ 3521 modules transformed.
'getAugmentedNamespace' is not exported by commonjsHelpers.js, imported by __vite-browser-external?commonjs-proxy
file: __vite-browser-external?commonjs-proxy:1:75
1: import * as __viteBrowserExternal from "__vite-browser-external"; import { getAugmentedNamespace } from "commonjsHelpers.js"; export default /*@__PURE__*/getAugmentedNamespace(__viteBrowserExternal);
                                                                              ^
error during build:
Error: 'getAugmentedNamespace' is not exported by commonjsHelpers.js, imported by __vite-browser-external?commonjs-proxy

zipang avatar Nov 04 '22 16:11 zipang

Any updates on this issue? v24.0.0 and still has issue.

pdmshrestha avatar Jan 02 '23 19:01 pdmshrestha

Same issue still with v24.0.1 Could not resolve import "commonjsHelpers.js"

Is this being addressed?

vtron avatar Feb 02 '23 22:02 vtron

I just tried this setting out and confirmed that it is still happening.

I am not using Vite, but I am am using Web Dev Server https://modern-web.dev/docs/dev-server/overview/ with Storybook, so I am setting strict-requires on the plugin through that config.

The issue seems to be that I am using an ES Module @.***/client-api) which imports a commonjs library.

The imports are for "global/window.js", "core-js/ and "qs".

Everything works fine when I have commonjs plugin active and I don't import the library I am having issues with.

On Fri, Feb 3, 2023 at 12:41 AM Lukas Taegert-Atkinson < @.***> wrote:

Did you try

build: { commonjsOptions: { strictRequires: true } }

in your Vite config?

— Reply to this email directly, view it on GitHub https://github.com/rollup/plugins/issues/986#issuecomment-1415361927, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABFXK7EC6RL5O7CLBY6TLDWVTAC5ANCNFSM5DHI7CGQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

vtron avatar Feb 06 '23 17:02 vtron

I also have this issue using vite --version: vite/4.1.4 darwin-x64 node-v18.14.0 vite dev server works. When i try to build i get RollupError:

"getAugmentedNamespace" is not exported by "commonjsHelpers.js", imported by "/opt/app/node_modules/react-use/esm/index.js?commonjs-proxy".
file: /opt/app/node_modules/react-use/esm/index.js?commonjs-proxy:1:9
1: import { getAugmentedNamespace } from "commonjsHelpers.js"; import * as esm from "/opt/app/node_modules/react-use/esm/index.js"; export default /*@__PURE__*/getAugmentedNamespace(esm);

When i add react-use to commonjsOptions.ignore, the error jumps to the next lib:

"getAugmentedNamespace" is not exported by "commonjsHelpers.js", imported by "/opt/app/node_modules/react-popper/lib/esm/index.js?commonjs-proxy".
file: /opt/app/node_modules/react-popper/lib/esm/index.js?commonjs-proxy:1:9
1: import { getAugmentedNamespace } from "commonjsHelpers.js"; import * as esm from "/opt/app/node_modules/react-popper/lib/esm/index.js"; export default /*@__PURE__*/getAugmentedNamespace(esm);

What am i missing? Any hints on investigating this?

igl avatar Mar 15 '23 09:03 igl

I am using Rollup to create an npm pacakge and I have the following versions:

"rollup": "^3.29.4",
"@rollup/plugin-commonjs": "^25.0.7",

I can see in the bundle file that the plugin adds the line import * as commonjsHelpers from 'commonjsHelpers.js';. However, when I install the package on another project I get the above errors. Inspecting what is actually in the npm package, I cannot find the file "commonjsHelpers.js". Could it be a misconfiguration of the plugin?

A simplified rollup.config.ts version:

// omitting imports to save space

const rollupConfiguration = [
	{
		input: ['./src/index.tsx'],
		external: [...Object.keys(pkg.peerDependencies || {}), /@babel\/runtime/],
		output: [
			{
				file: pkg.main,
				format: 'cjs',
				sourcemap: !production,
			},
			{
				file: pkg.module,
				format: 'es',
				exports: 'named',
				sourcemap: !production,
			},
		],
		plugins: [
			nodeResolve(),
			commonjs({
				sourceMap: !production,				
			}),
			babel({
				exclude: 'node_modules/**',
				presets: ['@babel/preset-react', ['@babel/preset-env']],
				babelrc: false,
				babelHelpers: 'runtime',
				plugins: ['@babel/plugin-transform-runtime'],
			}),
			postcss({
				extract: true,
				modules: false,
				use: ['sass'],
			}),
			typescript({
				sourceMap: !production,
				inlineSources: !production,
				target: 'es6',
			}),
			production && terser(),
		],
	},
];

export default rollupConfiguration;

cr4dle avatar Oct 25 '23 15:10 cr4dle

  • rollup 3.29.4
  • @rollup/plugin-commonjs 25.0.7

Trying out and adding some babel/rollup plugins:

pnpm dlx create-remix@latest --template remix-run/remix/templates/unstable-vite-express

I also got that kind of error:

"getAugmentedNamespace" is not exported by "commonjsHelpers.js", imported by "remix-vite-experimental/node_modules/.pnpm/[email protected]/node_modules/core-js/internals/fails.js?commonjs-proxy".

Beginning of stack:

error during build:
RollupError: "getAugmentedNamespace" is not exported by "commonjsHelpers.js", imported by "/Users/RomuQuan/Documents/devserver/workspace/remix-vite-experimental/node_modules/.pnpm/[email protected]/node_modules/core-js/internals/fails.js?commonjs-proxy".
    at error (remix-vite-experimental/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:2287:30)
    at Module.error (remix-vite-experimental/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:13745:16)
    at Module.traceVariable (remix-vite-experimental/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:14175:29)
    at ModuleScope.findVariable (remix-vite-experimental/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:12615:39)
    at Identifier.bind (remix-vite-experimental/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:8319:40)
import { unstable_vitePlugin as remix } from "@remix-run/dev";
import { defineConfig } from "vite";
import tsconfigPaths from "vite-tsconfig-paths";
import babel from 'vite-plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import { nodeResolve } from '@rollup/plugin-node-resolve';

export default defineConfig({
  plugins: [
    nodeResolve(),
    commonjs(),
    babel(),
    remix(),
    tsconfigPaths()
  ],
});

soundstep avatar Nov 16 '23 09:11 soundstep

@cr4dle I also can't find the file commonjsHelpers.js

soundstep avatar Nov 16 '23 10:11 soundstep

how to resolve it ?

kkkkkcnm avatar Feb 04 '24 09:02 kkkkkcnm