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

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

Open
danielgindi opened this issue Sep 1, 2021 · 23 comments
Open

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

danielgindi opened this issue Sep 1, 2021 · 23 comments
Assignees

Comments

@danielgindi
Copy link
Contributor

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 "�commonjsHelpers.js";
import { __exports as mongodb } from "\u0000/Users/user/git/server/node_modules/mongodb/index.js?commonjs-exports"

export default commonjsHelpers.commonjsRequire("/$$rollup_base$$/node_modules/mongodb/index.js", "/$$rollup_base$$/node_modules/mongodb");

@lukastaegert this looks like it's originating from the latest refactor during the circular dependencies support. While mongodb cannot be rolled up normally as it has severe circular dependencies, it seems to not be able to be rolled up dynamically too due to this bug. It looks like this should have been a reexport of __exports or at least *.
I tried to look into this and have not found what causes this to compose in such a way.
It's probably line 228 in index.js, but how do we make it play well with the other stuff that's being shoved in there?

@lukastaegert
Copy link
Member

Seems to be resolved by #1038

@phihu
Copy link

phihu commented Jan 11, 2022

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...

@emensch
Copy link

emensch commented Feb 8, 2022

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

@phihu
Copy link

phihu commented Mar 3, 2022

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

@mihaisavezi
Copy link

v22.0.0 release and problem still exists

try transforming to commonjs the deepmerge npm module

@b-houghton
Copy link

b-houghton commented Jun 6, 2022

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";

@Songkeys
Copy link

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

@jimblue
Copy link

jimblue commented Jul 18, 2022

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

@Ssis53

This comment was marked as duplicate.

@mhogara
Copy link

mhogara commented Aug 25, 2022

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

@enjikaka
Copy link

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".

@jcoglan
Copy link

jcoglan commented Sep 21, 2022

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.

@nickcipriani
Copy link

nickcipriani commented Sep 21, 2022

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)

@zipang
Copy link

zipang commented Nov 4, 2022

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

@pdmshrestha
Copy link

pdmshrestha commented Jan 2, 2023

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

@vtron
Copy link

vtron commented Feb 2, 2023

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

Is this being addressed?

@vtron
Copy link

vtron commented Feb 6, 2023 via email

@igl
Copy link

igl commented Mar 15, 2023

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?

@cr4dle
Copy link

cr4dle commented Oct 25, 2023

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;

@soundstep
Copy link

soundstep commented Nov 16, 2023

  • 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/core-js@3.33.2/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/core-js@3.33.2/node_modules/core-js/internals/fails.js?commonjs-proxy".
    at error (remix-vite-experimental/node_modules/.pnpm/rollup@3.29.4/node_modules/rollup/dist/es/shared/node-entry.js:2287:30)
    at Module.error (remix-vite-experimental/node_modules/.pnpm/rollup@3.29.4/node_modules/rollup/dist/es/shared/node-entry.js:13745:16)
    at Module.traceVariable (remix-vite-experimental/node_modules/.pnpm/rollup@3.29.4/node_modules/rollup/dist/es/shared/node-entry.js:14175:29)
    at ModuleScope.findVariable (remix-vite-experimental/node_modules/.pnpm/rollup@3.29.4/node_modules/rollup/dist/es/shared/node-entry.js:12615:39)
    at Identifier.bind (remix-vite-experimental/node_modules/.pnpm/rollup@3.29.4/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
Copy link

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

@kkkkkcnm
Copy link

kkkkkcnm commented Feb 4, 2024

how to resolve it ?

@niyuanfa
Copy link

how to resolve it ?

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

No branches or pull requests