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

Unable to build with webpack after v2 #66

Closed
esetnik opened this issue Dec 28, 2020 · 8 comments
Closed

Unable to build with webpack after v2 #66

esetnik opened this issue Dec 28, 2020 · 8 comments
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@esetnik
Copy link

esetnik commented Dec 28, 2020

5:29:56 AM: $ react-scripts build
5:29:59 AM: Creating an optimized production build...
5:32:37 AM: 
5:32:37 AM: Treating warnings as errors because process.env.CI = true.
5:32:37 AM: Most CI servers set it automatically.
5:32:37 AM: 
5:32:37 AM: Failed to compile.
5:32:37 AM: 
5:32:37 AM: ./node_modules/typed-usa-states/dist/index.js
5:32:37 AM: Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
5:32:37 AM: ./node_modules/typed-usa-states/dist/states.js
5:32:37 AM: Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
5:32:37 AM: ./node_modules/typed-usa-states/dist/states-with-zipcodes.js
5:32:37 AM: Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
5:32:37 AM: ./node_modules/typed-usa-states/dist/states-with-population.js
5:32:37 AM: Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
5:32:37 AM: ./node_modules/typed-usa-states/dist/states-with-counties.js
5:32:37 AM: Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
5:32:37 AM: ./node_modules/typed-usa-states/dist/states-with-area.js
5:32:37 AM: Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
5:32:37 AM: ./node_modules/typed-usa-states/dist/states-full.js
5:32:37 AM: Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
5:32:37 AM: ./node_modules/typed-usa-states/dist/cities.js
5:32:37 AM: Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
@scriptex
Copy link
Owner

scriptex commented Dec 28, 2020

Hi, @esetnik
I have tested this using create-react-app and was able to reproduce the issue.
A new patch has been released to npm which handles this issue.
Can you please try installing version 2.0.1 and see if the issue persists?
Thanks for reporting this!

@scriptex scriptex self-assigned this Dec 28, 2020
@scriptex scriptex added bug Something isn't working good first issue Good for newcomers labels Dec 28, 2020
@esetnik
Copy link
Author

esetnik commented Dec 30, 2020

@scriptex The issue is solved when using react-scripts build but not when using react-scripts start.

@scriptex
Copy link
Owner

Hm, okay, looks like something is missing...
I will take a look when I have time, most likely after the holidays :)

@scriptex
Copy link
Owner

scriptex commented Jan 4, 2021

Hi again, @esetnik, Happy New Year!

I've setup a new project with create-react-app and installed the latest version of typed-usa-states.
I didn't see any issues when running yarn start or yarn build.

I actually did a pretty simple check if everything works. This is the default App.js file:

import logo from './logo.svg';
import './App.css';

import {
	usaStates,
	usaCities,
	usaStatesFull,
	usaStatesWithArea,
	usaStatesWithCounties,
	usaStatesWithPopulation,
	usaStatesWithZipCodes,
} from 'typed-usa-states';

console.log(
	usaStates,
	usaCities,
	usaStatesFull,
	usaStatesWithArea,
	usaStatesWithCounties,
	usaStatesWithPopulation,
	usaStatesWithZipCodes
);

function App() {
	return (
		<div className="App">
			<header className="App-header">
				<img src={logo} className="App-logo" alt="logo" />
				<p>
					Edit <code>src/App.js</code> and save to reload.
				</p>
				<a
					className="App-link"
					href="https://reactjs.org"
					target="_blank"
					rel="noopener noreferrer"
				>
					Learn React
				</a>
			</header>
		</div>
	);
}

export default App;

The app gets correctly built and I am able to see the logs in the browser console.

Can you please show me how you use the package? Maybe a small demo or a code sample, just to get the idea of your use case.

@esetnik
Copy link
Author

esetnik commented Jan 4, 2021

Happy New Year to you too and thanks for getting back to me on this.

I'm using it basically the same way as you, except I am running this in a docker container and I noticed something interesting. If I give the container access to large amounts of memory and run yarn start then it does eventually finish building the project, however the webpack process takes a long time and consumes upwards of 8GB of memory. When I run the same process on my CI environment it fails with out of memory exceptions. The biggest difference from your code example is that I use typescript in my CRA project. I don't face either of these issues if I revert back to typed-usa-states@1.1.1

@scriptex
Copy link
Owner

scriptex commented Jan 4, 2021

Can you try to import the array you need directly?

I mean instead of using import { usaStates } from 'typed-usa-states' to use import { usaStates } from 'typed-usa-states/dist/states'.

I think this has to do with the way webpack works - it imports the whole index file which contains several pretty large arrays. Then it processes the large dataset and you run out of memory, this is particularly visible in a container environment where the RAM is not enough.

The workaround above will import only the array which you need (you can also import others instead of the example I have).

Let me know if this makes any difference.

@scriptex
Copy link
Owner

scriptex commented Jan 8, 2021

Hi, @esetnik, did you try what I suggested? Can you please let me know if the issue still persists.

@esetnik
Copy link
Author

esetnik commented Jan 9, 2021

@scriptex this solved the issue. Thanks!

@esetnik esetnik closed this as completed Jan 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants