Can't import ES6 modules in plugins
See original GitHub issueWhat would you like?
We discovered that we can’t import ES6 modules in the Cypress plugin file without this error:
/Volumes/workplace/package/src/test_package/node_modules/test_module/es6/test_directory/test.js:10
import * as t from 'io-ts/es6';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at wrapSafe (internal/modules/cjs/loader.js:1051:16)
at Module._compile (internal/modules/cjs/loader.js:1101:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1166:10)
at Module.load (internal/modules/cjs/loader.js:981:32)
at Module._load (internal/modules/cjs/loader.js:881:14)
at Function.Module._load (electron/js2c/asar.js:769:28)
at Module.require (internal/modules/cjs/loader.js:1023:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (/Volumes/workplace/package/src/test_package/cypress/plugins/index.ts:11:1)
at Module._compile (internal/modules/cjs/loader.js:1145:30)
at Module.m._compile (/Users/redacted/Library/Caches/Cypress/5.5.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/ts-node/src/index.ts:536:23)
at Module._extensions..js (internal/modules/cjs/loader.js:1166:10)
at Object.require.extensions.<computed> [as .ts] (/Users/redacted/Library/Caches/Cypress/5.5.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/ts-node/src/index.ts:539:12)
at Module.load (internal/modules/cjs/loader.js:981:32)
at Module._load (internal/modules/cjs/loader.js:881:14)
at Function.Module._load (electron/js2c/asar.js:769:28)
Why is this needed?
This is needed so that we can import ES6 modules that are necessary to be run as a node server process inside of the plugin index.ts
. We would like the option to either modify the ts-node configuration, or be able to configure the babel transpilation before the plugin is loaded and accessed.
We have managed to find our own workaround for now. See my colleague’s comment on this issue.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:7
Top Results From Across the Web
'Directory import is not supported resolving ES modules' with ...
With ES6 modules you can not (yet?) import directories. Your import should look like this: import database from "./database/index.js".
Read more >@rollup/plugin-commonjs - npm
A Rollup plugin to convert CommonJS modules to ES6, ... Some require calls cannot be resolved statically to be translated to imports, e.g.....
Read more >How to Bundle JavaScript With Rollup — Step-by-Step Tutorial
rollup-plugin-commonjs , which coverts CommonJS modules to ES6, which stops them from breaking Rollup. Install both plugins with the following command: npm ...
Read more >16. Modules - Exploring JS
3 Imports and exports must be at the top level #. As explained in more detail later, the structure of ES6 modules is...
Read more >Upgrade your Node app: From CommonJS to ES Modules
4) Fix imports and exports ... cjs-to-es6 converts const package = require('package') to import package from 'package' and const localFile = ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think you need to use
require
syntax in the plugins file. So something likeconst t = require('io-ts/es6')
should work.Any update on this? I have the exact same problem as @DiegoMcDipster described