Skip to content

inflected stopped working with upgrade to 1.0. #3254

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

Closed
timscott opened this issue Oct 8, 2017 · 3 comments
Closed

inflected stopped working with upgrade to 1.0. #3254

timscott opened this issue Oct 8, 2017 · 3 comments

Comments

@timscott
Copy link

timscott commented Oct 8, 2017

Is this a bug report?

Unsure

Can you also reproduce the problem with npm 4.x?

Yes

Which terms did you search for in User Guide?

"inlfected"
"camelize is not defined"
"not defined"

Environment

  1. node -v: 8.5.0
  2. npm -v: 4.6.1
  3. yarn --version (if you use Yarn): 1.0.2
  4. npm ls react-scripts (if you haven’t ejected): [email protected]

Then, specify:

  1. Operating system: OSX
  2. Browser and version (if relevant):

Steps to Reproduce

  1. Create app with with v0.9.5
  2. yarn add inflected
  3. Add code like:
import {camelize} from 'inflected';
const foo = camelize('foo_bar');
  1. yarn start
  2. In browser cause code in step 3 to run.
  3. It works!
  4. yarn upgrade [email protected]
  5. Repeat steps 4-5.
  6. See error: Uncaught ReferenceError: camelize is not defined
  7. Change the code in step 3:
const camelize = require('inflected').camelize;
const foo = camelize('foo_bar');
  1. Repeat steps 3-4
  2. It works again!

Expected Behavior

No error.

Actual Behavior

Get error: Uncaught ReferenceError: camelize is not defined

Reproducible Demo

(Paste the link to an example project and exact instructions to reproduce the issue.)

@timscott timscott changed the title inflected stopped working with upgrade to 1.0.0. inflected stopped working with upgrade to 1.0.13. Oct 8, 2017
@timscott timscott changed the title inflected stopped working with upgrade to 1.0.13. inflected stopped working with upgrade to 1.0. Oct 8, 2017
@timscott
Copy link
Author

timscott commented Oct 15, 2017

I have discovered the issue. It happens when calling a function from an imported module inside a dynamic require. This worked fine in 0.9.5 but not ^1.0.0.

Here is a minimal repro:

// src/index.js

import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

ReactDOM.render(<App />, document.getElementById('root'));
// src/App.jsx

import React, {Component} from 'react';
import {camelize} from 'inflected';

const App = () => {
  const MyComponent = require(`./${camelize('my_component', true)}/View`).default;
  return <MyComponent />;
};

export default App;
// src/MyComponent/View.jsx

import React from 'react';

const MyComponentView = () => <p>Hello</p>;

export default MyComponentView;

It can be worked around by extracting the call to a prior line, like so:

  const folder = camelize('my_component', true);
  const MyComponent = require(`./${folder}/View`).default;

I'm fine with the workaround, but I will leave this issue open in case this scenario should be supported.

@Timer
Copy link
Contributor

Timer commented Oct 16, 2017

Please open an issue with webpack with that reproduction case.

@gaearon
Copy link
Contributor

gaearon commented Jan 8, 2018

I'll close since there's not much we can do, and webpack is better positioned to solve this on their side.

@gaearon gaearon closed this as completed Jan 8, 2018
@lock lock bot locked and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants