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

createCookieSessionStorage is no longer exported server-runtime in v1.3.3 #2503

Closed
garth opened this issue Mar 25, 2022 · 11 comments
Closed

Comments

@garth
Copy link

garth commented Mar 25, 2022

What version of Remix are you using?

v1.3.3

Steps to Reproduce

Upgrade from v1.3.2 where server-runtime exported createCookieSessionStorage and now it is no longer there.

Expected Behavior

It should still be exported.

Actual Behavior

x

@bndkt
Copy link

bndkt commented Mar 26, 2022

Same for createCloudflareKVSessionStorage, since upgrading from 1.3.2 to 1.3.3 it throws with:

No matching export in "node_modules/@remix-run/cloudflare-pages/esm/index.js" for import "createCloudflareKVSessionStorage"

@VioletBuse
Copy link

I have this issue as well

@pcattori
Copy link
Contributor

We expect users to import from one of our concrete server runtime packages (i.e. @remix-run/node or @remix-run/cloudflare) rather than import directly from @remix-run/server-runtime.

We don't currently consider @remix-run/server-runtime to be an intended public API for users, so we refactored it. Specifically we replaced the functions that depend on internal crypto sign/unsign globals (like createCookieSessionStorage and createCloudflareKVSessionStorage) with factory functions that explicitly take crypto implementations and give you back the function (for example, see this code in @remix-run/node).


If you have a specific use-case that somehow requires importing directly from @remix-run/server-runtime rather than one of our concrete server runtime packages, feel free to reopen.

@garth
Copy link
Author

garth commented Mar 27, 2022

@pcattori for everyone who cannot use the remix package directly (due to it modifying node_modules), the advice we got was to import from the packages behind that have the actually implementation. In this case it was @remix-run/server-runtime.

if I update the import from @remix-run/server-runtime to @remix-run/node I get the following error:

export const sessionStorage = createCookieSessionStorage({
                               ^
TypeError: (0 , import_server_runtime.createCookieSessionStorage) is not a function

@pcattori
Copy link
Contributor

@garth Previously we recommended importing from remix via "magic" imports that relied on modifying node_modules/, but we're moving away from that in favor of importing directly from server runtime packages (see #2359). We're actively working on updating our docs, examples, etc... to use this new recommended approach.

Could you provide more info about the error you're seeing e.g. what your usage looks like and what file the error points to?

@pcattori
Copy link
Contributor

I created a new Remix app using Remix App Server and then added this to app/root.tsx:

import { createCookieSessionStorage } from "@remix-run/node";

export const loader = () => {
  const sessionStorage =
    createCookieSessionStorage({
      // a Cookie from `createCookie` or the same CookieOptions to create one
      cookie: {
        name: "__session",
        secrets: ["r3m1xr0ck5"],
        sameSite: "lax",
      },
    });
  console.log(sessionStorage)
  return null
}

Using v1.3.3 and this works locally for me. I'm able to hit localhost:3000 with my browser and see the session storage functions getting logged.

@garth
Copy link
Author

garth commented Mar 27, 2022

I had many imports from @remix-run/server-runtime, so went through the project and replaced them all with @remix-run/node and remove the server-runtime from my package.json and that seems to have fixed it.

Glad to hear that you will update the docs. Clearer instructions will help clarify a lot of details that we are currently getting from snippets from twitter or elsewhere.

@supachaidev
Copy link
Contributor

supachaidev commented Mar 28, 2022

@pcattori
Since Cloudflare Pages environment uses Web Crypto (Web Crypto APIs) instead of Node crypto, how can we use Remix createCookieSessionStorage function in Cloudflare Pages environment?

The cookie-signature lib on which @remix-run/node depends uses Node crypto which Pages environment does not support.

Any Web Crypto implementation for sign and unsign functions that Remix createCookieFactory function take?

Thank you.


Update:

Now I make it work by copying crypto implementation in @remix-run/cloudflare to crypto.ts file and import those 2 functions (sign and unsign) to use.

However, I cannot npm install @remix-run/cloudflare to a Remix Pages template. So I have to create crypto.ts in the project as a single file instead of using the exported functions from the @remix-run/cloudflare lib.

Here is the error when trying to npm install @remix-run/cloudflare in a Remix Pages template project.

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: remix-app-template@undefined

@pcattori
Copy link
Contributor

@supachaidev yes you should use @remix-run/cloudflare as your server runtime package. Sounds like you might be seeing the same thing as #2504

@tonymartin-dev
Copy link

A few months after the last comment in this issue, when I updated to v1.7.2, it turns out createCookieSessionStorage is no longer exported from @remix-run/node.
image

However, it seems that i can import it from @remix-run/server-runtime. Did this change again?

@MichaelDeBoey
Copy link
Member

@tonymartin-dev createCookieSessionStorage is still exported by @remix-run/node

export {
createCookie,
createCookieSessionStorage,
createMemorySessionStorage,
createSessionStorage,
} from "./implementations";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants