Skip to content

Can't initialize test with Jest if a component use aliplayer-react #9

Open
@fky2015

Description

@fky2015

When trying to test for component use aliplayer-react, an error triggered in aliplayer-react/lib/index.js indicates that ES6 syntax import used outside the module.

  ● Test suite failed to run

    .../node_modules/aliplayer-react/lib/index.js:12
    import React, { useEffect, useRef, useMemo } from 'react';
    ^^^^^^

    SyntaxError: Cannot use import statement outside a module

      1 | import React, { Component } from 'react'
    > 2 | import Player from "aliplayer-react";
        | ^
      3 | import './index.less';
      4 | 
      5 | export default class AliyunPlayer extends Component {

      at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:537:17)
      at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:579:25)
      at Object.<anonymous> (src/components/AliyunPlayer/index.jsx:2:1)

I believe that Jest is a Node environment and ES6 syntax is still an experimental feature in Node.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions