Cannot use import statement outside a module
Retanaar opened this issue · 5 comments
Hi,
I received error message while trying to run tests
import React from 'react';
^^^^^^
SyntaxError: Cannot use import statement outside a module
my cucumber.js profile
const common = [
'src//specs//.feature',
'--require-module ts-node/register',
'--require-module jsdom-global/register',
'--require src//specs/step-definitions//.steps.{ts,tsx}',
'--format progress-bar'
].join(' ');
module.exports = {
default: common
};
runing tests with ./node_modules/.bin/cucumber-js -p default
I have the same issue with react-typescript project,
After checking around for an hour I concluded its in the ts config file,
changing the module to commonjs value solved it.
"module": "commonjs",
Same here. After trying @moshebeeri’s solution, i get
Cannot find module 'node_modules/cucumber-pretty'
Installing cucumber-pretty
or @cucumber/pretty-formatter
does not fix it. :/
Btw. the tsconfig.json is the same our app uses to start. So I would prefer not to change it.
Sorry to come to this after almost 2 years, but I don't do frontend dev nearly at all, so I don't know what libraries are even involved in reproducing this.
Could one of you, if you are still facing this issue, provide a minimal reproduction repo?
A single hello-world component with a test that always passes should suffice.
Btw. the tsconfig.json is the same our app uses to start. So I would prefer not to change it.
As a side note, you can add a tsconfig.json file inside your step_definitions
folder, extending the definition from your app and modifying what you want to be different. The ts-node module will use the correct file.
{
"extends": "../tsconfig.json",
"compilerOptions": {
"module": "commonjs"
}
}
It should not be necessary, but I thought it was nice to share 😄
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.
There hasn't been any activity on this issue for 67 days. Closing it as Spoiled.