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

Uncaught SyntaxError: Identifier '_$1' has already been declared #2726

Closed
ashubham opened this issue Feb 26, 2019 · 13 comments · Fixed by #2737
Closed

Uncaught SyntaxError: Identifier '_$1' has already been declared #2726

ashubham opened this issue Feb 26, 2019 · 13 comments · Fixed by #2737

Comments

@ashubham
Copy link

ashubham commented Feb 26, 2019

  • Rollup Version: 1.3.0
  • Operating System (or Browser): OSX
  • Node Version: 10.11.0

How Do We Reproduce?

Simple config, which worked with version 1.1.2

{
    input: input,
    treeshake: false,
    output: {
        dir: `${OUTPUT_DIR}/module`,
        format: 'es',
        sourcemap: false,
        indent: false
    },
    perf: true,
    plugins: plugins
}

Expected Behavior

Should create a bundle, which runs in the browser

Actual Behavior

Console error Uncaught SyntaxError: Identifier '_$1' has already been declared

@lukastaegert
Copy link
Member

Hello @ashubham, this looks like a serious issue but without the actual code, I fear we will have a hard time tracking it down as we need to rely solely on guesswork. If you can reduce it to a small example exposing the error, this would be awesome, but any reproduction will do.

@lukastaegert
Copy link
Member

Note also that there is not identifier _$1 in the 1.3.0 distributed version of rollup, so maybe this is related to some code in the unspecified "plugins"?

@ashubham
Copy link
Author

ashubham commented Feb 27, 2019

Sorry for the incomplete info:

The list of plugins:

let plugins = [
    resolve({
        jsnext: true,
        browser: true
    }),
    commonjs({ sourceMap: false }),
    includePaths({
        paths: ['app/.tmp/ts-out']
    }),
    json({
        compact: true
    })
];

We have a large codebase, I am not sure of a small enough reproducible sample, but let me try.

@lukastaegert
Copy link
Member

I see. So if I understand you correctly, the error prevents you from bundling your code at all (instead of your bundled code throwing a runtime error)?

If that is the case, then somewhere in the codebase (rollup itself or plugins, but I already checked rollup) there is an identifier _$1 that is declared twice. An error stack trace would really help to identify the culprit.

Beyond that it sounds strange that a rollup update alone would cause this error. Were other plugins updated as well? When you downgrade just Rollup, what is the first exact version that exposes the error? If it turns out to be one of the plugins, the same question would apply.

@ashubham
Copy link
Author

ashubham commented Feb 28, 2019

@lukastaegert No actually the bundled code throws the above error, when run in the browser.

  • The other plugins are not updated.
  • Version 1.3 causes the error.
  • Version 1.1.2 does not.

I have not done a binary search for the breaking version, but can do if you need me to.

@lukastaegert
Copy link
Member

I feared as much. Unfortunately version 1.2 contained a complete rewrite of the deconflicting logic so the version alone will not help too much in pinpointing what we overlooked. If you do not manage to produce a repro maybe someone else will stumble upon the same bug. I will also have another look if I can think of a scenario that I have overlooked once I find some time but no promises here.

@lukastaegert
Copy link
Member

Just a question, is this a single chunk build or does it involve multiple chunks?

@lukastaegert
Copy link
Member

lukastaegert commented Mar 1, 2019

I must admit I spent some time looking for potential holes in the deconflicting but cannot find any. If you cannot provide a complete reproduction, maybe you can provide a snippet of the generated code around the duplicate declarations of _$1?

It would be very helpful to know:

  • What kind of variables are the two conflicting _$1? E.g. top level var/const/let, top level function/class, nested variable, named import, default import, namespace import...?
  • What were their original names? Were both called _ or was one/both already called _$1 before bundling?

@ashubham
Copy link
Author

ashubham commented Mar 1, 2019

import { a as createCommonjsModule, b as commonjsGlobal, c as __decorate, d as Provide, e as CheckboxComponent, f as truthyFunction, g as scheduler, h as ngRequire, i as _$1, j as strings$c, k as blinkConstants_1, l as stringUtil_1, m as common, n as decode64, o as sage$1, p as sage$2, q as jsonConstants_1, r as falcon, s as dateUtil_4, t as dateUtil_37, u as logger_3, v as onUserLoggedOut, w as encode64, x as AlertComponentBase, y as alertConstants, z as ReportProblemDialog, A as Component, B as isAppEmbedded, C as events$8, D as BaseComponent, E as CancelablePromise$3, F as getUserActionFailureAlertContent, G as startWorkflow, H as setWorkflowProps, I as getUserActionSuccessAlertContent, J as endWorkflow, K as ShareDialogComponent, L as showLoading, M as hideLoading, N as getUserGuid, O as hasAdminPrivileges, P as PrincipalType, Q as collectEvent, R as editTable, S as getRequestId, T as transformTable, U as logger_2, V as flags, W as getInterpretations, X as getNLCompletions, Y as recordNLFeedback, Z as UserWorkflowActionTypes, _ as getTip, $ as setTip, a0 as callosum, a1 as getUserPreferenceProto, a2 as isA3Enabled, a3 as hasRAnalysisPrivilege, a4 as isSeasonalityDetectionEnabled, a5 as env$8, a6 as getRequestInfoObject, a7 as SageResponse, a8 as getCurrentLocale, a9 as SmartCheckboxCollectionConfig, aa as SmartCheckboxCollectionComponent, ab as getSharePrincipal, ac as PermissionsListComponent, ad as getWhiteListedEmailDomainsForReport, ae as AddPrincipalComponent, af as UIComponent, ag as PrincipalViewerComponent, ah as InputComponent, ai as registerForStringChanges, aj as getRouteParameter, ak as ScopedComponent, al as _$1, am as unwrapExports, an as VisualizationColumnModel, ao as numeral, ap as getSessionTimeZone, aq as dateUtil_10, ar as dateUtil_17, as as dateUtil_29, at as getRandomInteger, au as dateUtil_39, av as dateUtil_36, aw as dateUtil_1, ax as aggregateTypes, ay as dateUtil_23, az as show$2, aA as DialogSize, aB as getAggregationTypeLabelsMap, aC as dateUtil_26, aD as DataFilterComponent, aE as show$3, aF as dist_1, aG as typed_2, aH as sessionStore, aI as dateUtil_2, aJ as dateUtil_3, aK as logUserActionFailureEvent, aL as getFilterModelFromAnswerJson, aM as idbStorage, aN as RequestTypes, aO as isAnswerDisplayModePreferenceDisabled, aP as getPreference, aQ as getNewClientTrace, aR as AlertComponent, aS as getResponsiveBreakpoint, aT as getNoMatchAlertContent, aU as typed_1, aV as FILTER_MODEL_TYPES, aW as dateUtil_8, aX as dateUtil_12, aY as dateUtil_11, aZ as areMapTilesEnabled, a_ as browserInfo, a$ as isCustomCalendar, b0 as dateUtil_38, b1 as GeoConfig, b2 as getDataNotSupportedError, b3 as getNoDataAlertContent, b4 as UserAction$X, b5 as SCALING_CLASS_NAMES, b6 as AccordionListComponent, b7 as AccordionItemComponent, b8 as getCurrentPage, b9 as shouldOpenVizUrlInSameTab, ba as EmptyPagePlaceholderComponent, bb as arrayUtil_1, bc as setOpenAnswerEditPanel, bd as getOpenAnswerEditPanel, be as isCustomRSearchPageIntegrationEnabled, bf as isInlineAutoAnalysisEnabled, bg as getActionConfig, bh as hasDataDownloadPrivileges, bi as hasDataManagementPrivileges, bj as getAlertContentFromMessage, bk as isDelayedSearchEnabled, bl as setPreference, bm as isAnswerSpotiqSnapshotEnabled, bn as getSourcesList, bo as _Observable, bp as isFunction_1, bq as Subscription_1, br as tryCatch_1, bs as errorObject_1, bt as Subscriber_1, bu as root_1, bv as observable_1, bw as isObject_1, bx as isArray_1, by as Browsers, bz as browserName, bA as _Observable, bB as Subject, bC as getSources, bD as Circulator, bE as isQueryUpdateDebounced, bF as getSourcesModels, bG as setSources, bH as userActionTypeEnum, bI as isEnliteMetricsDisabled, bJ as getActiveSourceName, bK as isEnliteEnabled, bL as stringUtil_3, bM as arrayUtil_4, bN as arrayUtil_5, bO as getSageDataSource, bP as updateSourcesName, bQ as setSageDataSource, bR as unionOfSources, bS as subscribeToSourcesChanged, bT as isSearchIQModePreferred, bU as arrayUtil_3, bV as SelectComponent, bW as getUserDisplayName$1, bX as RadioButtonComponent, bY as getCurrentCanvasSubState, bZ as isEmbraceEnabled, b_ as getUserPrivileges, b$ as showSaveAsDialog, c0 as saveAs$1, c1 as getDocumentIdFromJson, c2 as save, c3 as showDialogToSaveDocumentBeforeShare, c4 as getShareDialogConfig, c5 as onDeleteAction, c6 as startMissingWorkflow, c7 as getUnsavedDocumentAlertConfig, c8 as invalidateCache$1, c9 as getUserSlackId, ca as localizedDateFormats, cb as getUserName$1, cc as getCanChangePassword, cd as getPreferredLocale, ce as isLocalizationEnabled, cf as supportedLocales, cg as shouldNotifyOnShare, ch as setNotifyOnShare, ci as changeLocale, cj as setPreferredLocale, ck as getExposedUserPreferences, cl as getMaxConcurrentDataCalls, cm as clear, cn as onRouteChange, co as getRouteParameters, cp as logger_5, cq as hasPrivilege, cr as showGlobalLoading, cs as hideGlobalLoading, ct as CheckboxCollectionComponent, cu as getHelpConfig, cv as bach, cw as hasUserDataUploadPrivileges, cx as showAnchoredLoadingIndicator, cy as DialogCloseState, cz as getA3PinboardExpiryTime, cA as LogicalColumn, cB as $root, cC as disableScalingIfNeeded, cD as isAnomalyExplanationEnabled, cE as terminateWorkflow, cF as isPinboardSpotiqSnapshotEnabled, cG as TitleDescriptionComponent, cH as typed_3, cI as areTransformationsDisabledForVizEmbed, cJ as isPoweredFooterHiddenForVizEmbed, cK as isSessionRecordingEnabled, cL as isSamlEnabled, cM as getSignUpBtnText, cN as getSignUpBtnLink, cO as autoRedirectToSamlLogin, cP as wasManuallyLoggedOut, cQ as doLogin, cR as isSignUpEnabled, cS as MetadataItemSelector, cT as MetadataItemType, cU as isAnswerDisabled, cV as stringUtil_2, cW as getLast401Path, cX as onWorkflowComplete, cY as isFoolscapPdfDownloadEnabled, cZ as hasJobSchedulingPrivileges, c_ as isSchedulingJobEnabled, c$ as generateUUID, d0 as CUSTOM_CALENDAR_DEFAULT, d1 as CUSTOM_CALENDAR_NONE, d2 as getAvailableCalendarNames, d3 as CUSTOM_CALENDAR_DATATYPES, d4 as initializeScaling, d5 as terminateScaling, d6 as isDimensionlessAggregationType, d7 as getUserCreateTime, d8 as getClusterName, d9 as getUserPrivilegesBitMap, da as getClusterId, db as version, dc as logger_1, dd as logger_4, de as getAggregateLabel, df as getSupportedAggregationTypes, dg as arrayUtil_2, dh as specialDataValueFormat_1, di as specialDataValueFormat_2, dj as specialDataValueFormat_3, dk as specialDataValueFormat_4, dl as specialDataValueFormat_5, dm as numberUtil_5, dn as numberUtil_6, do as numberUtil_10, dp as numberUtil_7, dq as numberUtil_9, dr as numberUtil_2, ds as numberUtil_8, dt as numberUtil_11, du as numberUtil_12, dv as dateUtil_22, dw as dateUtil_21, dx as dateUtil_24, dy as dateUtil_25, dz as dateUtil_5, dA as dateUtil_7, dB as dateUtil_9, dC as dateUtil_30, dD as dateUtil_31, dE as dateUtil_32, dF as dateUtil_33, dG as dateUtil_34, dH as dateUtil_35, dI as dateUtil_27, dJ as dateUtil_28, dK as dateUtil_40, dL as dateUtil_18, dM as dateUtil_6, dN as getQueryParameters, dO as registerInits, dP as runAfterInjectorCreated, dQ as getQuarterStartMonth, dR as momentLocaleFileLoader, dS as initEventCollector, dT as isWalkmeEnabled, dU as appReady, dV as logger_6, dW as authenticate, dX as updateResources, dY as initAvailableCustomCalendars, dZ as onUserLoggedIn, d_ as isNPSEnabled, d$ as isStyleCustomizationEnabled, e0 as initialize$1, e1 as fetchSystemConfig, e2 as isWalkmeTestEnvEnabled, e3 as init$5, e4 as initWorkflowService, e5 as initWorkflowFlush, e6 as init$6, e7 as setDefaultAnchorSelector, e8 as isSessionActive, e9 as isLoggedIn, ea as DynamicController } from './chunk-1064b093.js';

See duplicate i as _$1 and al as _$1 in the above snippet. These are named imports. And from the usage in the code is seems to be an alias to lodash. We import lodash like a default commonjs style import import _ from 'lodash' in our unbundled source code.

If we look at the chunk referenced above we see lodash is being exported twice on two different namespaces:

look for lodash as i and lodash as al. That seems to be a part of the problem here.

chunk-1064b093.js

export { createCommonjsModule as a, commonjsGlobal as b, __decorate as c, Provide as d, CheckboxComponent$1 as e, truthyFunction as f, scheduler as g, ngRequire as h, lodash as i, strings as j, blinkConstants_1 as k, stringUtil_1 as l, common as m, decode64 as n, sage as o, sage$1 as p, jsonConstants_1 as q, falcon as r, dateUtil_4 as s, dateUtil_37 as t, logger_3 as u, onUserLoggedOut as v, encode64 as w, AlertComponentBase as x, alertConstants as y, ReportProblemDialog as z, Component as A, isAppEmbedded as B, events as C, BaseComponent as D, CancelablePromise as E, getUserActionFailureAlertContent as F, startWorkflow as G, setWorkflowProps as H, getUserActionSuccessAlertContent as I, endWorkflow as J, ShareDialogComponent as K, showLoading as L, hideLoading as M, getUserGuid as N, hasAdminPrivileges as O, PrincipalType as P, collectEvent as Q, editTable as R, getRequestId as S, transformTable as T, logger_2 as U, flags as V, getInterpretations as W, getNLCompletions as X, recordNLFeedback as Y, UserWorkflowActionTypes as Z, getTip as _, setTip as $, callosum as a0, getUserPreferenceProto as a1, isA3Enabled as a2, hasRAnalysisPrivilege as a3, isSeasonalityDetectionEnabled as a4, env as a5, getRequestInfoObject as a6, SageResponse as a7, getCurrentLocale as a8, SmartCheckboxCollectionConfig as a9, SmartCheckboxCollectionComponent as aa, getSharePrincipal as ab, PermissionsListComponent as ac, getWhiteListedEmailDomainsForReport as ad, AddPrincipalComponent as ae, UIComponent as af, PrincipalViewerComponent as ag, InputComponent as ah, registerForStringChanges as ai, getRouteParameter as aj, ScopedComponent as ak, lodash as al, unwrapExports as am, VisualizationColumnModel as an, numeral as ao, getSessionTimeZone as ap, dateUtil_10 as aq, dateUtil_17 as ar, dateUtil_29 as as, getRandomInteger as at, dateUtil_39 as au, dateUtil_36 as av, dateUtil_1 as aw, aggregateTypes as ax, dateUtil_23 as ay, show as az, DialogSize as aA, getAggregationTypeLabelsMap as aB, dateUtil_26 as aC, DataFilterComponent as aD, show$1 as aE, dist_1 as aF, typed_2 as aG, sessionStore as aH, dateUtil_2 as aI, date

I tried manually removing the rogue 2nd duplicate import. But then it complained about another duplicate name, so it seems there are multiple of these.

FWIW, the problem goes away if I do inlineDynamicImports: true in the config as it creates a single bundle.

@lukastaegert
Copy link
Member

Thanks a lot! In fact this looks very similar to an issue we fixed in 1.3.2, could you try again with that version? If it is the same issue, then you will still have the double exports (there is a technical reason for that that is not so easy to solve) but the second import will be omitted, fixing the syntax error.

@ashubham
Copy link
Author

ashubham commented Mar 4, 2019

Actually, the above issue is hit with using rollup 1.4.0. Do you believe something might have reintroduced this in 1.4 if yes, I can try using 1.3.2

@lukastaegert
Copy link
Member

lukastaegert commented Mar 5, 2019

No, that is unlikely. However thanks to your help, I found another case I overlooked, hope to post a fix soon:

https://rollupjs.org/repl?version=1.4.1&shareable=JTdCJTIybW9kdWxlcyUyMiUzQSU1QiU3QiUyMm5hbWUlMjIlM0ElMjJtYWluLmpzJTIyJTJDJTIyY29kZSUyMiUzQSUyMmltcG9ydCUyMGZvbyUyMGZyb20lMjAnLiUyRnByb3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BJTIybXlCdW5kbGUlMjIlMkMlMjJhbWQlMjIlM0ElN0IlMjJpZCUyMiUzQSUyMiUyMiU3RCUyQyUyMmdsb2JhbHMlMjIlM0ElN0IlN0QlN0QlMkMlMjJleGFtcGxlJTIyJTNBbnVsbCU3RA==

@lukastaegert
Copy link
Member

Ok, would be nice if you could

npm install rollup/rollup#gh-2726-different-default-exports-referencing-original

and see if this Rollup version fixes your problem.

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

Successfully merging a pull request may close this issue.

2 participants