Skip to content

netlify-cms-app import failed to resolve with astro's react integration #51

Open
@JasperDeLanghe

Description

@JasperDeLanghe

Running into the following error:

Screenshot_20221215_203933

Seems to be related to #34 , but with react() instead of vue() added as integration.
Makes no difference if putting it before or after NetlifyCMS() in the config.
The admin dashboard is working perfectly fine without the react integration and dependencies.

Will provide a cleaned repo to reproduce the issue later.

Activity

JasperDeLanghe

JasperDeLanghe commented on Dec 15, 2022

@JasperDeLanghe
Author

Here's a link to the repo: astro-netlifycms-react

And a trace of the failed netlify deploy:

8:55:44 PM: $ yarn build
8:55:44 PM: yarn run v1.22.19
8:55:44 PM: $ astro build
8:55:45 PM: 07:55:45 PM [build] output target: static
8:55:45 PM: 07:55:45 PM [build] Collecting build info...
8:55:45 PM: 07:55:45 PM [build] Completed in 9ms.
8:55:45 PM: 07:55:45 PM [build] Building static entrypoints...
8:55:47 PM: 07:55:47 PM [build] Completed in 1.32s.
8:55:47 PM: 
8:55:47 PM:  building client 
8:55:47 PM: [vite]: Rollup failed to resolve import "netlify-cms-app" from "virtual:astro-netlify-cms/user-config".
8:55:47 PM: This is most likely unintended because it can break your application at runtime.
8:55:47 PM: If you do want to externalize this module explicitly add it to
8:55:47 PM: `build.rollupOptions.external`
8:55:47 PM:  error   [vite]: Rollup failed to resolve import "netlify-cms-app" from "virtual:astro-netlify-cms/user-config".
8:55:47 PM:   This is most likely unintended because it can break your application at runtime.
8:55:47 PM:   If you do want to externalize this module explicitly add it to
8:55:47 PM:   `build.rollupOptions.external`
8:55:47 PM:   File:
8:55:47 PM:     /opt/build/repo/node_modules/vite/dist/node/chunks/dep-5605cfa4.js:45832:19
8:55:47 PM:   Code:
8:55:47 PM:       45831 |         if (!importer || !/\?commonjs-external$/.test(importer)) {
8:55:47 PM:     > 45832 |             throw new Error(`[vite]: Rollup failed to resolve import "${id}" from "${importer}".\n` +
8:55:47 PM:             |                   ^
8:55:47 PM:       45833 |                 `This is most likely unintended because it can break your application at runtime.\n` +
8:55:47 PM:       45834 |                 `If you do want to externalize this module explicitly add it to\n` +
8:55:47 PM:       45835 |                 `\`build.rollupOptions.external\``);
8:55:47 PM:     
8:55:47 PM:   Stacktrace:
8:55:47 PM: Error: [vite]: Rollup failed to resolve import "netlify-cms-app" from "virtual:astro-netlify-cms/user-config".
8:55:47 PM: This is most likely unintended because it can break your application at runtime.
8:55:47 PM: If you do want to externalize this module explicitly add it to
8:55:47 PM: `build.rollupOptions.external`
8:55:47 PM:     at onRollupWarning (file:///opt/build/repo/node_modules/vite/dist/node/chunks/dep-5605cfa4.js:45832:19)
8:55:47 PM:     at onwarn (file:///opt/build/repo/node_modules/vite/dist/node/chunks/dep-5605cfa4.js:45603:13)
8:55:47 PM:     at Object.onwarn (file:///opt/build/repo/node_modules/rollup/dist/es/shared/rollup.js:23263:13)
8:55:47 PM:     at ModuleLoader.handleResolveId (file:///opt/build/repo/node_modules/rollup/dist/es/shared/rollup.js:22158:26)
8:55:47 PM:     at file:///opt/build/repo/node_modules/rollup/dist/es/shared/rollup.js:22119:26
8:55:47 PM:     at processTicksAndRejections (node:internal/process/task_queues:96:5)
8:55:47 PM: error Command failed with exit code 1. (https://ntl.fyi/exit-code-1)
8:55:47 PM: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
JasperDeLanghe

JasperDeLanghe commented on Dec 15, 2022

@JasperDeLanghe
Author

After looking through some source code I found this return [react(), NetlifyCMSIntegration]; at the bottom of the integration index.ts. Seems I don't have to separately add the react integration myself and can just leave it out 🤷‍♂️

My tsx components seem to be working perfectly after leaving it out, rebuilding and serving.

Would be helpful to have this piece of information in the README imo

danxschz

danxschz commented on Dec 18, 2022

@danxschz

I'm getting the exact same error message using astro-netlify-cms version 0.5.0 with the react integration. This is the trace:

[vite] Internal server error: Failed to resolve import "netlify-cms-app" from "virtual:astro-netlify-cms/user-config". Does the file exist?
  Plugin: vite:import-analysis
  File: virtual:astro-netlify-cms/user-config:2:24
  1  |  
  2  |  import * as NCMS from 'netlify-cms-app';
     |                         ^
  3  |  
  4  |  export default {
      at formatError (/node_modules/vite/dist/node/chunks/dep-5605cfa4.js:40281:46)
      at TransformContext.error (/node_modules/vite/dist/node/chunks/dep-5605cfa4.js:40277:19)
      at normalizeUrl (/node_modules/vite/dist/node/chunks/dep-5605cfa4.js:37145:33)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at async TransformContext.transform (/node_modules/vite/dist/node/chunks/dep-5605cfa4.js:37278:47)
      at async Object.transform (/node_modules/vite/dist/node/chunks/dep-5605cfa4.js:40534:30)
      at async loadAndTransform (/node_modules/vite/dist/node/chunks/dep-5605cfa4.js:36921:29)
delucis

delucis commented on Dec 18, 2022

@delucis
Owner

Thanks @danxschz! Any chance you can share your project or a minimal reproduction, e.g. on StackBlitz?

danxschz

danxschz commented on Dec 18, 2022

@danxschz

Thanks @danxschz! Any chance you can share your project or a minimal reproduction, e.g. on StackBlitz?

https://github.com/danxschz/studio-mndz

delucis

delucis commented on Dec 18, 2022

@delucis
Owner

Thanks! But it looks like this repo doesn’t have the integration added? Maybe you need to push some local changes?

image

danxschz

danxschz commented on Dec 18, 2022

@danxschz

Thanks! But it looks like this repo doesn’t have the integration added? Maybe you need to push some local changes?

image

Yes sorry about that, just pushed the changes

delucis

delucis commented on Dec 18, 2022

@delucis
Owner

Perfect, thank you. I’m very curious what’s going on. Made my own minimal set-up that didn’t do this — https://stackblitz.com/edit/github-u7myzp?file=astro.config.mjs — so it’s helpful to have your example to test with.

delucis

delucis commented on Dec 18, 2022

@delucis
Owner

OK, so one quick fix: downgrading to React 17 and installing netlify-cms-app as a direct dependency does seem to fix this:

npm i {,@types/}{react,react-dom}@^17 netlify-cms-app

Don’t understand why this would be necessary in one project and not another but will keep investigating.

AntGervais

AntGervais commented on Feb 17, 2023

@AntGervais

OK, so one quick fix: downgrading to React 17 and installing netlify-cms-app as a direct dependency does seem to fix this:

npm i {,@types/}{react,react-dom}@^17 netlify-cms-app

Don’t understand why this would be necessary in one project and not another but will keep investigating.

Thank you @delucis, I had the same problem and now it's ok 👌

zanhk

zanhk commented on Sep 17, 2023

@zanhk

For anyone using pnpm and having the same problem, remember to shamefully-hoist packages

// place on .npmrc
shamefully-hoist=true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      `netlify-cms-app` import failed to resolve with astro's react integration · Issue #51 · delucis/astro-netlify-cms