Skip to content

Bug: SyntaxError when trying to import named exports from "react" #18941

@wereHamster

Description

@wereHamster

React version: 16.13.1

Steps To Reproduce

import React, { useState } from "react";
console.log(React, useState)

The import declaration is taken straight from the hooks documentation (https://reactjs.org/docs/hooks-intro.html), hence why I expected it to work.

Save as bug.mjs, run with node bug.mjs (node v13 or later).

The current behavior

file:///…/bug.mjs:1
import React, { useState } from "react";
                ^^^^^^^^
SyntaxError: The requested module 'react' does not provide an export named 'useState'
    at ModuleJob._instantiate (internal/modules/esm/module_job.js:92:21)
    at async ModuleJob.run (internal/modules/esm/module_job.js:107:20)
    at async Loader.import (internal/modules/esm/loader.js:179:24)

The expected behavior

No Syntax Error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution: StaleAutomatically closed due to inactivityStatus: UnconfirmedA potential issue that we haven't yet confirmed as a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions