Closed jaehanley closed 7 months ago
@jaehanley
What exact version are you using? Is it 7.1.0 or older?
What kind of build are you using? CommonJS? ES Module? UMD?
What version of NodeJS are you using?
What build system are you using and his version?
Also please provide a full example. I am not able to reproduce the issue.
@eXon the same issue.
const cookies = new Cookies()
const cookieToken = cookies.get('token')
@Luke-SNAW By creating a new NextJS app, exporting it to static files, I was not able to reproduce the issue. I simply added your code to a useEffect and it was working as expected, without the error. Are you able to share a full project with the issue?
@eXon I've created this repository to reproduce the issue. When running development versions of Next 12, the package functions as expected, however when built and ran in production mode with yarn build && yarn start
, the above error will manifest.
@jaehanley After investigating, it seems like the error happens when enabling swcMinify
.
It minifies:
this.update = () => {
if (!this.HAS_DOCUMENT_COOKIE) {
return;
}
const previousCookies = this.cookies;
this.cookies = parse_1(document.cookie);
this._checkChanges(previousCookies);
};
Into:
this.update = ()=>{
if (!this.HAS_DOCUMENT_COOKIE)
return;
let e = this.cookies;
this.cookies = e(document.cookie),
this._checkChanges(e)
}
It doesn't make any sense that e
is this.cookies
and used as a function. It must be a bug with the SWC version it is using.
The good news is this bug seems fixed in NextJS 13+. All I did is change the version and it worked. It means you have two choices:
Let me know if I can do anything else for you
In universal-cookie, introduced with v7.0.0, when calling the
get
method from a Cookies object, production builds result in a TypeError, "TypeError: e is not a function". We haven't changed anything in terms of how we initialize or use the Cookies class or get method between v6 and v7, so I believe this is some sort of build issue that got introduced with the changes from v7.Within the built Cookies class constructor: