Skip to content

Cannot use import statement outside a module #166

@simplisticated

Description

@simplisticated

Problem Description

Step 1

Run in terminal:

npx owl build --platform ios

Result:

** BUILD SUCCEEDED **

Step 2

Run in terminal:

npx owl test --platform ios

Result:

...
Jest encountered an unexpected token
...
SyntaxError: Cannot use import statement outside a module
...

Below you can find more technical information that may be related to this problem.

Environment

  • macOS 13.4.1
  • Xcode 14.3.1
  • react-native 0.72.4
  • react-native-owl 1.2.3

owl.config.json:

{
    "ios": {
      "workspace": "ios/ProjectName.xcworkspace",
      "scheme": "ProjectName",
      "configuration": "Release",
      "device": "iPhone 14"
    },
    "android": {
      "packageName": "com.projectname.app"
    },
    "report": true
  }

babel.config.js

const getPresets = (api) => {
  if (api.env('test')) {
    return [
      ['@babel/preset-env', {
        targets: { node: 'current' },
      }],
      '@babel/preset-typescript',
      'module:metro-react-native-babel-preset',
    ];
  }
  return ['module:metro-react-native-babel-preset'];
};

const getPlugins = (api) => {
  const result = [
    [
      'module-resolver',
      {
        alias: {
          '@src': './src',
        },
      },
    ],
  ];

  if (api.env('production')) {
    result.plugins.push('transform-remove-console');
  }

  return result;
};

module.exports = (api) => ({
  presets: getPresets(api),
  plugins: getPlugins(api),
});

package.json:

{
  "name": "ProjectName",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "lint": "eslint .",
    "lint:fix": "eslint --fix .",
    "start": "react-native start",
    "owl:build:ios": "owl build --platform ios",
    "owl:test:ios": "owl test --platform ios",
    "owl:test:ios:update": "owl test --platform ios --update",
    "owl:build:android": "owl build --platform android",
    "owl:test:android": "owl test --platform android",
    "owl:test:android:update": "owl test --platform android --update",
    "test": "jest --passWithNoTests"
  },
  "dependencies": {
    ...
  },
  "devDependencies": {
    "@babel/core": "^7.23.2",
    "@babel/preset-env": "^7.23.2",
    "@babel/preset-typescript": "^7.23.2",
    "@babel/runtime": "^7.20.0",
    "@react-native/eslint-config": "^0.72.2",
    "@react-native/metro-config": "^0.72.11",
    "@testing-library/jest-native": "^5.4.3",
    "@testing-library/react-native": "^12.3.0",
    "@tsconfig/react-native": "^3.0.0",
    "@types/jest": "^29.5.5",
    "@types/react": "^18.0.24",
    "@types/react-dom": "^18.2.10",
    "@types/react-test-renderer": "^18.0.0",
    "babel-jest": "^29.7.0",
    "babel-plugin-module-resolver": "^5.0.0",
    "babel-plugin-transform-remove-console": "^6.9.4",
    "eslint": "^8.49.0",
    "eslint-config-airbnb": "^19.0.4",
    "eslint-config-airbnb-typescript": "^17.1.0",
    "eslint-plugin-import": "^2.28.1",
    "eslint-plugin-jsx-a11y": "^6.7.1",
    "eslint-plugin-react": "^7.33.2",
    "eslint-plugin-react-hooks": "^4.6.0",
    "eslint-plugin-react-native": "^4.1.0",
    "jest": "^29.7.0",
    "metro-react-native-babel-preset": "0.76.8",
    "prettier": "^2.4.1",
    "react-dom": "^18.2.0",
    "react-native-owl": "^1.2.3",
    "react-test-renderer": "^18.2.0",
    "ts-jest": "^29.1.1",
    "typescript": "4.8.4"
  },
  "engines": {
    "node": ">=16"
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions