Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import files with .js extension for browser support #2695

Closed
bennypowers opened this issue Nov 3, 2017 · 2 comments
Closed

Import files with .js extension for browser support #2695

bennypowers opened this issue Nov 3, 2017 · 2 comments

Comments

@bennypowers
Copy link

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

@markerikson
Copy link
Contributor

What's the use case for import * as Redux from '../node_modules/redux/src/index.js? That seems like a very odd way to try to import things.

@timdorr
Copy link
Member

timdorr commented Nov 3, 2017

It's a side effect of the layout from an npm install.

For now, because the browser module story is still settling, I don't think this is a thing we should necessarily handle ourselves. Services like unpkg are providing rewritten modules to support this kind of thing right now. I'm sure we're getting close to an express middleware that will do the same thing.

Also, based on how things will be changing with #2358, this kind of thing will be a non-issue in the near future too.

@timdorr timdorr closed this as completed Nov 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants