https://github.com/statico/nextjs-with-async-lib
https://github.com/statico/nextjs-with-async-lib
Last synced: 10 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/statico/nextjs-with-async-lib
- Owner: statico
- Created: 2018-04-17T05:16:00.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2021-04-30T18:39:00.000Z (about 5 years ago)
- Last Synced: 2025-02-21T20:15:09.567Z (over 1 year ago)
- Language: JavaScript
- Size: 87.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# nextjs with async library demo
## Problem
I need a library to be accessible from Node on the server-side and from NextJS React pages.
I would like to take advantage of the new async/await syntax because it makes the code remarkably cleaner and easier to debug.
## Bug
This demo shows weirdness when trying to include a JavaScript library with async functions inside of a NextJS page:
```
$ yarn install
$ yarn exec next
WARNING Compiled with 2 warnings
warning in ./pages/index.js
24:18-21 "export 'foo' was not found in '../lib/test'
warning in ./pages/index.js
24:62-65 "export 'foo' was not found in '../lib/test'
TypeError: Cannot assign to read only property 'exports' of object '#'
...
```
And visiting http://localhost:3000 --

I can't change `lib/test.js` to ES6-style `export`s because Node will complain with `SyntaxError: Unexpected token`. What am I doing wrong?
### Versions
- NextJS 5.1
- Node 9.11.1
### Related issues
- https://github.com/webpack/webpack/issues/4039
- https://github.com/zeit/next.js/issues/3650
- https://github.com/zeit/next.js/issues/1472
- https://github.com/zeit/next.js/issues/1735
### pages/index.js
```javascript
import { foo } from '../lib/test'
export default () =>
hello {String(typeof foo)}
```
### lib/test.js
```javascript
async function foo () {}
module.exports = { foo }
```