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

custom imports bundling breaks when used in API routes and SSR pages #1151

Closed
thescientist13 opened this issue Sep 9, 2023 · 0 comments · Fixed by #1152 or #1120
Closed

custom imports bundling breaks when used in API routes and SSR pages #1151

thescientist13 opened this issue Sep 9, 2023 · 0 comments · Fixed by #1152 or #1120
Assignees
Labels
alpha.5 bug Something isn't working CLI documentation Greenwood specific docs feature New feature or request Plugins Greenwood Plugins SSR v0.29.0
Milestone

Comments

@thescientist13
Copy link
Member

thescientist13 commented Sep 9, 2023

Summary

If trying to do something like this with custom imports

import styles from './component.css';

Rollup throws an error on trying to bundle on the CSS file when used in the aforementioned contexts from the issue title

        SyntaxError: Unexpected token (1:4)
        at pp$4.raise (file:///Users/owenbuckley/Workspace/project-evergreen/greenwood/node_modules/rollup/dist/es/shared/rollup.js:19420:13)
        at pp$9.unexpected (file:///Users/owenbuckley/Workspace/project-evergreen/greenwood/node_modules/rollup/dist/es/shared/rollup.js:16714:8)
        at pp$9.semicolon (file:///Users/owenbuckley/Workspace/project-evergreen/greenwood/node_modules/rollup/dist/es/shared/rollup.js:16691:66)
        at pp$8.parseExpressionStatement (file:///Users/owenbuckley/Workspace/project-evergreen/greenwood/node_modules/rollup/dist/es/shared/rollup.js:17174:8)
        at pp$8.parseStatement (file:///Users/owenbuckley/Workspace/project-evergreen/greenwood/node_modules/rollup/dist/es/shared/rollup.js:16907:24)
        at pp$8.parseTopLevel (file:///Users/owenbuckley/Workspace/project-evergreen/greenwood/node_modules/rollup/dist/es/shared/rollup.js:16771:21)
        at Parser.parse (file:///Users/owenbuckley/Workspace/project-evergreen/greenwood/node_modules/rollup/dist/es/shared/rollup.js:16543:15)
        at Function.parse (file:///Users/owenbuckley/Workspace/project-evergreen/greenwood/node_modules/rollup/dist/es/shared/rollup.js:16593:35)
        at Graph.contextParse (file:///Users/owenbuckley/Workspace/project-evergreen/greenwood/node_modules/rollup/dist/es/shared/rollup.js:22959:38)
        at Object.transform (/Users/owenbuckley/Workspace/project-evergreen/greenwood/node_modules/@web/rollup-plugin-import-meta-assets/src/rollup-plugin-import-meta-assets.js:65:24) {
      pos: 4,
      loc: Position { line: 1, column: 4 },
      raisedAt: 5,
      code: 'PLUGIN_ERROR',
      plugin: 'rollup-plugin-import-meta-assets',
      hook: 'transform',
      id: '/Users/owenbuckley/Workspace/project-evergreen/greenwood/packages/plugin-import-css/test/cases/exp-serve.ssr/src/components/card.css',
      watchFiles: [
        '/Users/owenbuckley/Workspace/project-evergreen/greenwood/packages/plugin-import-css/test/cases/exp-serve.ssr/.greenwood/_products.js',
        '/Users/owenbuckley/Workspace/project-evergreen/greenwood/packages/plugin-import-css/test/cases/exp-serve.ssr/src/pages/products.js',
        '/Users/owenbuckley/Workspace/project-evergreen/greenwood/packages/plugin-import-css/test/cases/exp-serve.ssr/src/components/card.js',
        '/Users/owenbuckley/Workspace/project-evergreen/greenwood/packages/plugin-import-css/test/cases/exp-serve.ssr/src/services/products.js',
        '/Users/owenbuckley/Workspace/project-evergreen/greenwood/packages/cli/src/lib/execute-route-module.js',
        '/Users/owenbuckley/Workspace/project-evergreen/greenwood/packages/plugin-import-css/test/cases/exp-serve.ssr/src/components/card.css'
      ]
    }
  

You can see a full reproduction here

Details

It looks like there is also a "bug" on @web/rollup-plugin-import-meta-assets in which it will only emit references found in new URL as an asset, instead of chunk (at least for .js files). This leads to 404s when resolving these assets

          Serve command with API specific behaviors for an HTML ("fragment") API
    Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/owenbuckley/Workspace/project-evergreen/greenwood/packages/plugin-import-css/test/cases/exp-serve.ssr/public/api/assets/card.css' imported from /Users/owenbuckley/Workspace/project-evergreen/greenwood/packages/plugin-import-css/test/cases/exp-serve.ssr/public/api/assets/card-78d7632f.js
        at new NodeError (node:internal/errors:393:5)
        at finalizeResolution (node:internal/modules/esm/resolve:323:11)
        at moduleResolve (node:internal/modules/esm/resolve:916:10)
        at defaultResolve (node:internal/modules/esm/resolve:1124:11)
        at nextResolve (node:internal/modules/esm/loader:163:28)
        at resolve (file:///Users/owenbuckley/Workspace/project-evergreen/greenwood/test/test-loader.js:21:12)
        at nextResolve (node:internal/modules/esm/loader:163:28)
        at ESMLoader.resolve (node:internal/modules/esm/loader:841:30)
        at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
        at ModuleWrap. (node:internal/modules/esm/module_job:76:40) {
      code: 'ERR_MODULE_NOT_FOUND'
    }
  

As seen in the linked reproduction above, we should make now make sure that .js files get emitted as a chunk.


As this is an experimental feature and will require a decent change to fix / support, will target this fix against the v0.29.0 alpha release line.

@thescientist13 thescientist13 added this to the 1.0 milestone Sep 9, 2023
@thescientist13 thescientist13 self-assigned this Sep 9, 2023
@thescientist13 thescientist13 added the Plugins Greenwood Plugins label Sep 10, 2023
@thescientist13 thescientist13 moved this from 🏗 In progress to 👀 In review in [Greenwood] Phase 9 - Standards and Conventions Sep 23, 2023
@thescientist13 thescientist13 added feature New feature or request documentation Greenwood specific docs labels Oct 7, 2023
@thescientist13 thescientist13 mentioned this issue Oct 14, 2023
25 tasks
@thescientist13 thescientist13 linked a pull request Oct 14, 2023 that will close this issue
25 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
alpha.5 bug Something isn't working CLI documentation Greenwood specific docs feature New feature or request Plugins Greenwood Plugins SSR v0.29.0
Projects
No open projects
1 participant