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

TS cannot find type definitions for story editor when setting up a standalone editor #14014

Open
IvanNasonovIna opened this issue Feb 28, 2025 · 3 comments
Labels
Type: Bug Something isn't working

Comments

@IvanNasonovIna
Copy link

IvanNasonovIna commented Feb 28, 2025

Bug Description

I was trying to set up a standalone story editor and after following the steps described in the tutorial to set up a standalone story editor, if I import the editor, TS can't find type definitions Could not find a declaration file for module '@googleforcreators/story-editor'.

Expected Behaviour

Type definitions can be found correctly

Steps to Reproduce

  1. Set up a simple react project
  • using Vite:
    • run the command yarn create vite story-editor-standalone --template react-ts
    • downgrade to react 17 by running yarn add [email protected] [email protected] and yarn add -D @types/react@17 @types/react-dom@17 - as far as i know the story editor only works with react 17
    • since we changed the version of react we should change the way we render our app to the root, go into src/main.tsx and change the contents of the file to the following
import { StrictMode } from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./App.tsx";

ReactDOM.render(
  <StrictMode>
    <App />
  </StrictMode>,
  document.getElementById("root")
);
  • since we are using Vite, we need to do some additional changes for the app to work - Vite doesn't export the global object, so we need to export it ourselves, create the file named init.js in the src directory with the following contents:
window.global ||= window;
  • import this file in main.tsx before any other imports
import "./init";

import { StrictMode } from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./App.tsx";
...
  • now the project setup is complete and we can follow the steps of the tutorial, follow the steps until you import the editor component and you will see the error

Screenshots

Image

Additional Context

  • @googleforcreators/design-system version: "^0.1.202410011217",
  • @googleforcreators/element-library version: "^0.1.202410011217",
  • @googleforcreators/elements version: "^0.1.202410011217",
  • @googleforcreators/migration version: "^0.1.202410011217",
  • @googleforcreators/story-editor version: "^0.1.202410011217",
  • Operating System: MacOS
@IvanNasonovIna IvanNasonovIna added the Type: Bug Something isn't working label Feb 28, 2025
@IvanNasonovIna
Copy link
Author

Am I doing something wrong? Does this library not support TS yet? I see a lot of type definitions in dist-types, put the tsconfig.json inside the project is really strange and has a lot of errors& If this was discussed somewhere already I would love to have a link :)

Image

@IvanNasonovIna IvanNasonovIna changed the title TS cannot find type definitions for story editor TS cannot find type definitions for story editor црут ыуеештп гз ф ыефтвфдщту увшещк Feb 28, 2025
@IvanNasonovIna IvanNasonovIna changed the title TS cannot find type definitions for story editor црут ыуеештп гз ф ыефтвфдщту увшещк TS cannot find type definitions for story editor Feb 28, 2025
@IvanNasonovIna IvanNasonovIna changed the title TS cannot find type definitions for story editor TS cannot find type definitions for story editor when setting up a standalone editor Feb 28, 2025
@IvanNasonovIna
Copy link
Author

Also the setup was pretty rough, the docs on this seem really out of date, I ended up using Vite, because newer versions of webpack seem to have even more trouble running this library, and had to go through all these steps just to get it working

  • downgrade to react 17 by running yarn add [email protected] [email protected] and yarn add -D @types/react@17 @types/react-dom@17 - as far as i know the story editor only works with react 17
  • since we changed the version of react we should change the way we render our app to the root, go into src/main.tsx and change the contents of the file to the following
  • since we are using Vite, we need to do some additional changes for the app to work - Vite doesn't export the global object, so we need to export it ourselves, create the file named init.js in the src directory with the following contents

it would be really nice if someone could provide a more up-to-date tutorial on setting this up with modern tools, or at least recommended versions of webpack and libraries to use

@swissspidy
Copy link
Collaborator

Thanks for opening this issue.

The story-editor package is only partially written in TypeScript and thus the TS definitions are very incomplete. So as you see in the dist-types folder we don't ship much there. So yeah the message is expected I guess :)

As for the documentation, we don't have any Vite-specific guidance/tutorial at the moment, but appreciate the feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants