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

About module field in package.json #11

Closed
AllenFang opened this issue Apr 8, 2019 · 3 comments
Closed

About module field in package.json #11

AllenFang opened this issue Apr 8, 2019 · 3 comments
Assignees

Comments

@AllenFang
Copy link

AllenFang commented Apr 8, 2019

Hello @dai-shi, firstly, thanks for this awesome package, I just encounter a wired issue when I adopt this package. After deeply digging, i felt the root cause is about the "module field in package.json" probably.

The issue is when I running my application,I saw this error message:

./node_modules/react-hooks-global-state/src/index.js 68:6
Module parse failed: Unexpected token (68:6)
You may need an appropriate loader to handle this file type.
|   const setGlobalState = (name, update) => {
|     globalState = {
>       ...globalState,   <<<  something wrong here
|       [name]: updateValue(globalState[name], update),
|     };

My application stack is

  • next.js@7.0.0
  • yarn@1.12.3
  • node@9.10.0

The wired thing is when I use npm will fix this issue. So I try to clone this code and use npm link to do some local testing, I found if I remove module field in package.json or change it to dist/index.js will fix this issue certainly.

Seems like module is still proposal and not sure if there's any different when developer use yarn or npm install the package.

NOTE: You may aware that above error is from the source code(src) instead of dist in the runtime

Could we fix this issue just remove the module field or change it to dist/index.js

Thanks

@dai-shi
Copy link
Owner

dai-shi commented Apr 8, 2019

@AllenFang Thanks for reporting this.
I assumed that bundler that uses module can deal esnext, but it's not true in your case.
So, CRA is fine, but not for next.js. Let me take some time to investigate it and deal with it.

Meanwhile, you can import dist directly. Hope it helps for your use case.

import { createGlobalState } from 'react-hooks-global-state/dist';

@dai-shi dai-shi self-assigned this Apr 8, 2019
@AllenFang
Copy link
Author

you can import dist directly. Hope it helps for your use case.

oh, I forget I can do it 😄

Anyway, thanks your reply, you can decide to close this issue anytime.

@dai-shi
Copy link
Owner

dai-shi commented Apr 14, 2019

See also: vercel/next.js#706

I'd like to keep "module", unless we find a better way.

@dai-shi dai-shi closed this as completed Apr 14, 2019
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

2 participants