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

Absolute Twig template path causes "Unable to find template file" #46

Open
mle86 opened this issue Feb 4, 2025 · 2 comments
Open

Absolute Twig template path causes "Unable to find template file" #46

mle86 opened this issue Feb 4, 2025 · 2 comments

Comments

@mle86
Copy link

mle86 commented Feb 4, 2025

When using Twig Component name_prefix and an absolute Twig template path,
the bundle generates invalid internal paths
causing "Unable to find template file" errors.

The problem seems to stem from this line introduced in v0.1.2:
117c5a4#diff-128f62b2acd2d7742958dd6811d5271872143ab21521bb45f19231cbfb6e2281R32

Here, the twig.yaml paths are always prefixed with the project root dir.
This didn't happen before (when the template paths were ignored and join(projectDir, 'templates', templateDirectory) was used instead).

This works fine if the paths setting has relative paths only --
it breaks if there's an absolute path like in our twig.yaml config:

twig:
    file_name_pattern: '*.twig'
    paths: ['%kernel.project_dir%/templates']
    debug: '%kernel.debug%'
#

This gets resolved to /home/mle/project/home/mle/project/templates/components/ which doesn't exist of course.

Our twig_component.yaml file:

twig_component:
    anonymous_template_directory: 'components/'
    defaults:
        Library\Twig\Components\:
            template_directory: 'components/'
            name_prefix: 'Lib'
@mle86
Copy link
Author

mle86 commented Feb 4, 2025

Full error output:

$ yarn run sb dev -p 6006 --no-open --disable-telemetry

@storybook/core v8.4.4

WARN The following packages are incompatible with Storybook 8.4.4 as they depend on different major versions of Storybook packages:
WARN - @storybook/[email protected]
WARN  Repo: https://github.com/storybookjs/storybook/tree/next/code/addons/interactions
WARN - @storybook/[email protected]
WARN  Repo: https://github.com/storybookjs/storybook/tree/next/code/lib/test
WARN
WARN
WARN Please consider updating your packages or contacting the maintainers for compatibility details.
WARN For more on Storybook 8 compatibility, see the linked GitHub issue:
WARN https://github.com/storybookjs/storybook/issues/26031
info => Serving static files from ././assets/static at /
info => Serving static files from ././public at /
info => Serving static files from ././assets at /
info => Starting manager..
info => Starting preview..
[HPM] Proxy created: /  -> http://localhost:8000
[HPM] Proxy created: /  -> http://localhost:8000
info Addon-docs: using MDX3
info => Using implicit CSS loaders
info => Using default Webpack5 setup
<i> [webpack-dev-middleware] wait until bundle finished
37% building 1/2 entries 300/399 dependencies 27/141 modules
WARN Failed to parse template in '/home/mle/project/templates/components/A.html.twig': Error: Unable to find template file for component "Lib:B": Error: Qualified path resolution failed: we looked for the following paths, but none could be accessed.
WARN
WARN Source path: /home/mle/project/.yarn/__virtual__/@sensiolabs-storybook-symfony-webpack5-virtual-087534b99c/3/.yarn/berry/cache/@sensiolabs-storybook-symfony-webpack5-file-a2512ee2d9-10c0.zip/node_modules/@sensiolabs/storybook-symfony-webpack5/dist/server/Icon.html.twig
WARN Not found: /home/mle/project/.yarn/__virtual__/@sensiolabs-storybook-symfony-webpack5-virtual-087534b99c/3/.yarn/berry/cache/@sensiolabs-storybook-symfony-webpack5-file-a2512ee2d9-10c0.zip/node_modules/@sensiolabs/storybook-symfony-webpack5/dist/server/Icon.html.twig
WARN Not found: /home/mle/project/.yarn/__virtual__/@sensiolabs-storybook-symfony-webpack5-virtual-087534b99c/3/.yarn/berry/cache/@sensiolabs-storybook-symfony-webpack5-file-a2512ee2d9-10c0.zip/node_modules/@sensiolabs/storybook-symfony-webpack5/dist/server/Icon.html.twig.js
WARN Not found: /home/mle/project/.yarn/__virtual__/@sensiolabs-storybook-symfony-webpack5-virtual-087534b99c/3/.yarn/berry/cache/@sensiolabs-storybook-symfony-webpack5-file-a2512ee2d9-10c0.zip/node_modules/@sensiolabs/storybook-symfony-webpack5/dist/server/Icon.html.twig.json
WARN Not found: /home/mle/project/.yarn/__virtual__/@sensiolabs-storybook-symfony-webpack5-virtual-087534b99c/3/.yarn/berry/cache/@sensiolabs-storybook-symfony-webpack5-file-a2512ee2d9-10c0.zip/node_modules/@sensiolabs/storybook-symfony-webpack5/dist/server/Icon.html.twig.node
WARN Not found: /home/mle/project/.yarn/__virtual__/@sensiolabs-storybook-symfony-webpack5-virtual-087534b99c/3/.yarn/berry/cache/@sensiolabs-storybook-symfony-webpack5-file-a2512ee2d9-10c0.zip/node_modules/@sensiolabs/storybook-symfony-webpack5/dist/server/Icon.html.twig.jsx
WARN Not found: /home/mle/project/.yarn/__virtual__/@sensiolabs-storybook-symfony-webpack5-virtual-087534b99c/3/.yarn/berry/cache/@sensiolabs-storybook-symfony-webpack5-file-a2512ee2d9-10c0.zip/node_modules/@sensiolabs/storybook-symfony-webpack5/dist/server/Icon.html.twig.ts
WARN Not found: /home/mle/project/.yarn/__virtual__/@sensiolabs-storybook-symfony-webpack5-virtual-087534b99c/3/.yarn/berry/cache/@sensiolabs-storybook-symfony-webpack5-file-a2512ee2d9-10c0.zip/node_modules/@sensiolabs/storybook-symfony-webpack5/dist/server/Icon.html.twig.tsx
WARN Not found: /home/mle/project/.yarn/__virtual__/@sensiolabs-storybook-symfony-webpack5-virtual-087534b99c/3/.yarn/berry/cache/@sensiolabs-storybook-symfony-webpack5-file-a2512ee2d9-10c0.zip/node_modules/@sensiolabs/storybook-symfony-webpack5/dist/server/Icon.html.twig.mjs
WARN Not found: /home/mle/project/.yarn/__virtual__/@sensiolabs-storybook-symfony-webpack5-virtual-087534b99c/3/.yarn/berry/cache/@sensiolabs-storybook-symfony-webpack5-file-a2512ee2d9-10c0.zip/node_modules/@sensiolabs/storybook-symfony-webpack5/dist/server/Icon.html.twig.mts
WARN Not found: /home/mle/project/.yarn/__virtual__/@sensiolabs-storybook-symfony-webpack5-virtual-087534b99c/3/.yarn/berry/cache/@sensiolabs-storybook-symfony-webpack5-file-a2512ee2d9-10c0.zip/node_modules/@sensiolabs/storybook-symfony-webpack5/dist/server/Icon.html.twig.cts
WARN Not found: /home/mle/project/.yarn/__virtual__/@sensiolabs-storybook-symfony-webpack5-virtual-087534b99c/3/.yarn/berry/cache/@sensiolabs-storybook-symfony-webpack5-file-a2512ee2d9-10c0.zip/node_modules/@sensiolabs/storybook-symfony-webpack5/dist/server/Icon.html.twig.handlebars
WARN Not found: /home/mle/project/.yarn/__virtual__/@sensiolabs-storybook-symfony-webpack5-virtual-087534b99c/3/.yarn/berry/cache/@sensiolabs-storybook-symfony-webpack5-file-a2512ee2d9-10c0.zip/node_modules/@sensiolabs/storybook-symfony-webpack5/dist/server/Icon.html.twig.hbs
WARN
WARN Require stack:
WARN - /home/mle/project/.yarn/__virtual__/@sensiolabs-storybook-symfony-webpack5-virtual-087534b99c/3/.yarn/berry/cache/@sensiolabs-storybook-symfony-webpack5-file-a2512ee2d9-10c0.zip/node_modules/@sensiolabs/storybook-symfony-webpack5/dist/server/framework-preset.js
WARN - /home/mle/project/.yarn/__virtual__/@storybook-core-virtual-0a26476036/3/.yarn/berry/cache/@storybook-core-npm-8.4.4-e555a46534-10c0.zip/node_modules/@storybook/core/dist/common/index.cjs
WARN - /home/mle/project/.yarn/__virtual__/storybook-virtual-51d4343766/3/.yarn/berry/cache/storybook-npm-8.4.4-f2cb1dd4a5-10c0.zip/node_modules/storybook/dist/proxy.cjs
WARN - /home/mle/project/.yarn/__virtual__/storybook-virtual-51d4343766/3/.yarn/berry/cache/storybook-npm-8.4.4-f2cb1dd4a5-10c0.zip/node_modules/storybook/bin/index.cjs
/home/mle/project/.yarn/__virtual__/storybook-virtual-51d4343766/3/.yarn/berry/cache/storybook-npm-8.4.4-f2cb1dd4a5-10c0.zip/node_modules/storybook/bin/index.cjs:23
  throw error;
  ^

Error: Unable to determine template name for file "/home/mle/project/templates/components/A.html.twig":
    at base (/home/mle/project/.yarn/__virtual__/@sensiolabs-storybook-symfony-webpack5-virtual-087534b99c/3/.yarn/berry/cache/@sensiolabs-storybook-symfony-webpack5-file-a2512ee2d9-10c0.zip/node_modules/@sensiolabs/storybook-symfony-webpack5/src/server/framework-preset.ts:101:11)
    at base (/home/mle/project/.yarn/__virtual__/@sensiolabs-storybook-symfony-webpack5-virtual-087534b99c/3/.yarn/berry/cache/@sensiolabs-storybook-symfony-webpack5-file-a2512ee2d9-10c0.zip/node_modules/@sensiolabs/storybook-symfony-webpack5/src/server/framework-preset.ts:101:11)
    at Object.transform (/home/mle/.yarn/berry/cache/unplugin-npm-1.16.0-dff6a10977-10c0.zip/node_modules/unplugin/dist/webpack/loaders/transform.js:115:38)
    at LOADER_EXECUTION (/home/mle/.yarn/berry/cache/loader-runner-npm-4.3.0-9ca67df372-10c0.zip/node_modules/loader-runner/lib/LoaderRunner.js:132:14)
    at runSyncOrAsync (/home/mle/.yarn/berry/cache/loader-runner-npm-4.3.0-9ca67df372-10c0.zip/node_modules/loader-runner/lib/LoaderRunner.js:133:4)
    at iterateNormalLoaders (/home/mle/.yarn/berry/cache/loader-runner-npm-4.3.0-9ca67df372-10c0.zip/node_modules/loader-runner/lib/LoaderRunner.js:251:2)
    at /home/mle/.yarn/berry/cache/loader-runner-npm-4.3.0-9ca67df372-10c0.zip/node_modules/loader-runner/lib/LoaderRunner.js:224:4
    at /home/mle/project/.yarn/__virtual__/webpack-virtual-a88f77e3d8/3/.yarn/berry/cache/webpack-npm-5.96.1-1a1f8d3a52-10c0.zip/node_modules/webpack/lib/NormalModule.js:990:15
    at Array.eval (eval at create (/home/mle/.yarn/berry/cache/tapable-npm-2.2.1-8cf5ff3039-10c0.zip/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:12:1)
    at runCallbacks (/home/mle/.yarn/berry/cache/enhanced-resolve-npm-5.17.1-296305b69f-10c0.zip/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:45:15)

Node.js v20.12.1

@mle86
Copy link
Author

mle86 commented Feb 4, 2025

Changing twig.yaml to relative paths avoids this issue:

twig:
    # ...
    paths: ['templates']  # no %kernel.project_dir% !
    # ...

But lots of examples still show absolute paths.

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

No branches or pull requests

1 participant