Skip to content

Import files with .js extension for browser support #2695

Closed
@bennypowers

Description

@bennypowers

What is the current behavior?
index.js imports dependencies without file extensions:

import createStore from './createStore'
import combineReducers from './combineReducers'
import bindActionCreators from './bindActionCreators'
import applyMiddleware from './applyMiddleware'
import compose from './compose'
import warning from './utils/warning'

If a user were to import * as Redux from '../node_modules/redux/src/index.js, the browser would not be able to resolve createStore et al. as files.

A potential hitch is the lodash dependency in https://github.com/reactjs/redux/blob/53f3e1594b0754a7afcc416ec668e2b7f22573bf/src/combineReducers.js#L2 and https://github.com/reactjs/redux/blob/53f3e1594b0754a7afcc416ec668e2b7f22573bf/src/createStore.js#L1 which could likely be hitched by using a relative path like ../lodash/isPlainObject.js

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://jsfiddle.net or similar.

Can't figure out how to install npm deps in JSBin sorry ¯\_(ツ)_/¯

What is the expected behavior?

It would be ✨ Awesome ✨ to be able to import redux in the browser

// src/mymodules.js
import * as Redux from '../node_modules/redux/src/index.js'

👆 and it just works.

Which versions of Redux, and which browser and OS are affected by this issue? Did this work in previous versions of Redux?

AFAICT this affects all versions and all browsers.

If this suggestion seems reasonable to the maintainers, I'm happy to issue a pull request adding the file extensions and relative paths to import statements in /src/**/*.js

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions