Aaronius / penpal

A promise-based library for securely communicating with iframes via postMessage.
MIT License
381 stars 56 forks source link

Including penpal in babel producing errors #76

Closed onemantooo closed 2 years ago

onemantooo commented 2 years ago

Hi. I'm using penpal in my Rollup + TS project and getting a bunch of errors, when trying to include node_modules/penpal/**/*.js in babel processing. Babel is configured to support IE 11 (penpal is not used in this case, but syntax needs to be transpiled cause it's bundled in single file), so when i don't include penpal i'm getting a syntax error in IE, but when i include - everything seems working fine in IE also, but i got errors during build:

Errors & warns

(!) Error when using sourcemap for reporting an error: Can't resolve original location of error.
node_modules/penpal/lib/parent/connectToChild.js (3:12)
(!) Error when using sourcemap for reporting an error: Can't resolve original location of error.
node_modules/penpal/lib/parent/connectToChild.js (101:8)
(!) Error when using sourcemap for reporting an error: Can't resolve original location of error.
node_modules/penpal/lib/child/connectToParent.js (3:12)
(!) Error when using sourcemap for reporting an error: Can't resolve original location of error.
node_modules/penpal/lib/createLogger.js (3:12)
(!) Error when using sourcemap for reporting an error: Can't resolve original location of error.
node_modules/penpal/lib/createLogger.js (24:8)
(!) Error when using sourcemap for reporting an error: Can't resolve original location of error.
node_modules/penpal/lib/createDestructor.js (3:12)
(!) Error when using sourcemap for reporting an error: Can't resolve original location of error.
node_modules/penpal/lib/createDestructor.js (28:8)
(!) Error when using sourcemap for reporting an error: Can't resolve original location of error.
node_modules/penpal/lib/methodSerialization.js (4:12)
(!) Error when using sourcemap for reporting an error: Can't resolve original location of error.
node_modules/penpal/lib/startConnectionTimeout.js (3:12)
(!) Error when using sourcemap for reporting an error: Can't resolve original location of error.
node_modules/penpal/lib/startConnectionTimeout.js (33:8)
(!) Error when using sourcemap for reporting an error: Can't resolve original location of error.
node_modules/penpal/lib/parent/handleAckMessageFactory.js (3:12)
(!) Error when using sourcemap for reporting an error: Can't resolve original location of error.
node_modules/penpal/lib/parent/handleAckMessageFactory.js (68:8)
(!) Error when using sourcemap for reporting an error: Can't resolve original location of error.
node_modules/penpal/lib/parent/handleSynMessageFactory.js (3:12)
(!) Error when using sourcemap for reporting an error: Can't resolve original location of error.
node_modules/penpal/lib/parent/handleSynMessageFactory.js (32:8)
(!) Error when using sourcemap for reporting an error: Can't resolve original location of error.
node_modules/penpal/lib/parent/getOriginFromSrc.js (3:12)
(!) Error when using sourcemap for reporting an error: Can't resolve original location of error.
node_modules/penpal/lib/parent/getOriginFromSrc.js (61:8)
(!) Error when using sourcemap for reporting an error: Can't resolve original location of error.
node_modules/penpal/lib/parent/monitorIframeRemoval.js (3:12)
(!) Error when using sourcemap for reporting an error: Can't resolve original location of error.
node_modules/penpal/lib/parent/monitorIframeRemoval.js (36:8)
(!) Error when using sourcemap for reporting an error: Can't resolve original location of error.
node_modules/penpal/lib/parent/validateIframeHasSrcOrSrcDoc.js (3:12)
(!) Error when using sourcemap for reporting an error: Can't resolve original location of error.
node_modules/penpal/lib/parent/validateIframeHasSrcOrSrcDoc.js (14:8)
(!) Error when using sourcemap for reporting an error: Can't resolve original location of error.
node_modules/penpal/lib/child/handleSynAckMessageFactory.js (3:12)
(!) Error when using sourcemap for reporting an error: Can't resolve original location of error.
node_modules/penpal/lib/child/handleSynAckMessageFactory.js (58:8)
(!) Error when using sourcemap for reporting an error: Can't resolve original location of error.
node_modules/penpal/lib/connectCallSender.js (3:12)
(!) Error when using sourcemap for reporting an error: Can't resolve original location of error.
node_modules/penpal/lib/connectCallSender.js (136:8)
(!) Error when using sourcemap for reporting an error: Can't resolve original location of error.
node_modules/penpal/lib/connectCallReceiver.js (3:12)
(!) Error when using sourcemap for reporting an error: Can't resolve original location of error.
node_modules/penpal/lib/connectCallReceiver.js (115:8)
(!) Error when using sourcemap for reporting an error: Can't resolve original location of error.
node_modules/penpal/lib/errorSerialization.js (3:12)
(!) Error when using sourcemap for reporting an error: Can't resolve original location of error.
node_modules/penpal/lib/generateId.js (3:12)
(!) Error when using sourcemap for reporting an error: Can't resolve original location of error.
node_modules/penpal/lib/generateId.js (14:8)
/Users/me/GIT/widget/node_modules/core-js/internals/an-instance.jshttp://localhost:10001 -> /Users/ext.ymamedov/GIT/widget-next/dist/bundles
/Users/me/GIT/widget/node_modules/core-js/internals/array-method-has-species-support.js(!) `this` has been rewritten to `undefined`
https://rollupjs.org/guide/en/#error-this-is-undefined
node_modules/penpal/lib/parent/connectToChild.js
1: import { newArrowCheck as _newArrowCheck } from "\0rollupPluginBabelHelpers.js";
2: 
3: var _this = this;
               ^
4: 
5: import "core-js/modules/es.object.to-string.js";
...and 1 other occurrence
node_modules/penpal/lib/child/connectToParent.js
1: import { newArrowCheck as _newArrowCheck } from "\0rollupPluginBabelHelpers.js";
2: 
3: var _this = this;
               ^
4: 
5: import "core-js/modules/es.regexp.constructor.js";
...and 1 other occurrence
node_modules/penpal/lib/createLogger.js
1: import { newArrowCheck as _newArrowCheck } from "\0rollupPluginBabelHelpers.js";
2: 
3: var _this = this;
               ^
4: 
5: import "core-js/modules/es.array.concat.js";
...and 1 other occurrence

...and 13 other files

Babel config:

esmBundled: {
      presets: [
        [
          "@babel/env",
          {
            targets: {
              browsers: "ie >= 10, safari >= 10",
            },
            modules: "auto",
            spec: true,
            useBuiltIns: "usage",
            forceAllTransforms: true,
            corejs: {
              version: 3.9,
            },
          },
        ],
        "@babel/typescript",
      ],
      plugins: [
        [
          "module-resolver",
          {
            alias: {
              "@": "./src",
            },
          },
        ],
      ],
    },

Maybe you can help me solving this?

Aaronius commented 2 years ago

Hey @onemantooo. I'm not familiar with this error. From https://rollupjs.org/guide/en/#error-this-is-undefined, it looks like you might be able to play around with options.context and options.moduleContext. I don't have any particular insight into this, sorry! If you find out it's something wrong with Penpal, please let me know! Thanks!