Closed danabdn closed 1 month ago
@danabdn From the looks of it, I think your project may be missing some vite setup. Run h2 setup vite
. Afterwards, make sure to run npm install
(May need to clean out node_modules
and/or package-lock.json
)
I also recommend updating Hydrogen by using the h2 upgrade
command.
@danabdn From the looks of it, I think your project may be missing some vite setup. Run
h2 setup vite
. Afterwards, make sure to runnpm install
(May need to clean outnode_modules
and/orpackage-lock.json
)
I deleted node_modules and package-lock.json, ran the setup vite command (result: This project already has a Vite config file) and then tried npm run dev again and nothing. Just exits with code 1. I.e. the CLI has crashed and is not reporting anything.
Problem still present - code 1 suggests it's a crash with the CLI.
Okay - so I deduced there was a problem with the CLI (as above) and discovered that there was and upgrade available from v3.52.0 to v3.58.2. Now I get an actual error message...
Failed to load PostCSS config (searchPath: C:/GitHub/XXXX/hydrogen/hydrogen): [ReferenceError] module is not defined in ES module scope This file is being treated as an ES module because it has a '.js' file extension and 'C:\GitHub\XXXX\hydrogen\hydrogen\package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension. ReferenceError: module is not defined in ES module scope This file is being treated as an ES module because it has a '.js' file extension and 'C:\GitHub\XXXX\hydrogen\hydrogen\package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension. at file:///C:/GitHub/XXXX/hydrogen/hydrogen/postcss.config.js:1:1 at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
Guess I will review my package.json for any possible upgrades and look at the above error. Will let you know how I get on.
Step forward - to resolve the above error, you can rename postcss.config.js to postcss.config.cjs (or possibly just delete the file). Reference - https://github.com/QwikDev/qwik/issues/836
The web development server text now appears in the CLI :-)
However, when launching the web dev server in a browser, the following message is displayed on black background with white text.
ReferenceError: exports is not defined
AND /graphiql results in the same error message.
ReferenceError: exports is not defined
at C:/GitHub/XXXX/hydrogen/hydrogen/node_modules/typographic-base/index.es5.js:3:23
at Object.runViteModule (GitHub/XXXX/hydrogen/hydrogen/node_modules/@shopify/mini-oxygen/dist/vite/worker-entry.js:1171:17)
at ViteRuntime.directRequest (GitHub/XXXX/hydrogen/hydrogen/node_modules/@shopify/mini-oxygen/dist/vite/worker-entry.js:1026:78)
...
As mentioned by others, I would recommend reverting back to your original project, then do h2 upgrade
to update dependencies plus h2 setup vite
to start using Vite.
This last command already renames your postcss.config.js
to postcss.config.cjs
and it does the same for .eslintrc.js
.
Otherwise, if you prefer to do it manually, here's what we do in the command to have a reference of what you need to change: https://github.com/Shopify/hydrogen/blob/main/packages/cli/src/commands/hydrogen/setup/vite.ts#L52
However, when launching the web dev server in a browser, the following message is displayed on black background with white text.
This is unrelated to the first issue. The problem here is that typographic-base
uses CJS internally and you need to tell Vite to optimize it for ESM. You can see here how we do it in the demo-store: https://github.com/Shopify/hydrogen-demo-store/blob/main/vite.config.ts#L16
What is the location of your example repository?
Private
Which package or tool is having this issue?
Hydrogen
What version of that package or tool are you using?
Templates > Skeleton > Latest as of 15th April 2024 (package.json below)
What version of Remix are you using?
^2.8.0
Steps to Reproduce
Package.json
Expected Behavior
Actual Behavior
PROBLEM 1 - The web development server does not load - command exits with no error (or anything at all) and back to where you can type in the next command.
Running the npm run dev command (shown below), the terminal in VSCode just exits without displaying an error.
PS C:\GitHub\XXXX\hydrogen\hydrogen> npm run dev
PS C:\GitHub\XXXX\hydrogen\hydrogen>
PROBLEM 2 - A new file is created called "vite.config.ts.timestamp-xxxx.mjs (where x is a timestamp).
The content of the vite config file that is automatically created (every time I run npm run dev) outputs the following...
I cannot view my website locally anymore. I cannot develop my app. When I tried to run npm run dev with debug attached, there is a small popup that shows "Debug adapter process has terminated unexpectedly".
cli-hydrogen is 8.0.0 (based on the version number - most likely to be the culprit). It should at least give an error e.g. where about it encountered the error.
Now cannot do anything on the project. Any help appreciated or possibly indicate how I diagnose this critical error.
PS I've really been enjoying developing my Hydrogen project!
Edit: Stack Overflow issue submitted here