Skip to content

api platform no longer installs seamlessly with Symfony #58928

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

Closed
tacman opened this issue Nov 19, 2024 · 8 comments · Fixed by #59004
Closed

api platform no longer installs seamlessly with Symfony #58928

tacman opened this issue Nov 19, 2024 · 8 comments · Fixed by #59004

Comments

@tacman
Copy link
Contributor

tacman commented Nov 19, 2024

Symfony version(s) affected

7.1

Description

API Platform version(s) affected: 4.0

A simple install with a Symfony webapp used to work but now throws an error.

How to reproduce

symfony new MyApp  --webapp && cd MyApp
composer req api
bin/console make:entity -a Task -n
symfony server:start -d
symfony open:local --path=/api

image

The files themselves, e.g.
https://127.0.0.1:8029/assets/bundles/apiplatform/swagger-ui/swagger-ui-standalone-preset-4fec96b52efef25338c0ee2a2c2619e4.js

image

I've reported this in api-platform as well: api-platform/api-platform#2801

Possible Solution

No response

Additional Context

No response

@tacman tacman added the Bug label Nov 19, 2024
@tacman tacman changed the title api platform no longer installs seamlessly with Symfon api platform no longer installs seamlessly with Symfony Nov 19, 2024
@laszlopokoradi
Copy link

I am facing the same issue, my "resolution" was to remove a comment from the \vendor\api-platform\symfony\Bundle\Resources\public\graphiql\graphiql.min.js file.

This line contains a code example with import('./path/to/domAnimations').

@tacman
Copy link
Contributor Author

tacman commented Nov 20, 2024

Yep, this code is commented out.

// Asynchronous loading
/**
 * Used in conjunction with the `m` component to reduce bundle size.
 *
 * `m` is a version of the `motion` component that only loads functionality
 * critical for the initial render.
 *
 * `LazyMotion` can then be used to either synchronously or asynchronously
 * load animation and gesture support.
 *
 * ```jsx
 * // Synchronous loading
 * import { LazyMotion, m, domAnimations } from "framer-motion"
 *
 * function App() {
 *   return (
 *     <LazyMotion features={domAnimations}>
 *       <m.div animate={{ scale: 2 }} />
 *     </LazyMotion>
 *   )
 * }
 *
 * // Asynchronous loading
 * import { LazyMotion, m } from "framer-motion"
 *
 * function App() {
 *   return (
 *     <LazyMotion features={() => import('./path/to/domAnimations')}>
 *       <m.div animate={{ scale: 2 }} />
 *     </LazyMotion>
 *   )
 * }
 * ```
 *
 * @public
 */

Since assetmapper is not a javascript parser, it gets the paths it needs to resolve with a regex.

Perhaps this commit?
symfony/asset-mapper@21fe29b

Although that probably wasn't it because it just added unicode support.

Until recently, this issue threw a warning in the javascript console, but now it won't even load.

@tacman
Copy link
Contributor Author

tacman commented Nov 20, 2024

The regex grabs it, then

symfony/asset-mapper@21fe29b#diff-a6269ebc4116f5cfab61b63c4af5131c884e3f2267e442333760e1589de4b4eaR144-R169

I'll try to prepare a test maps some sort of fix.

@tacman
Copy link
Contributor Author

tacman commented Nov 20, 2024

I added a test, and am now attempting to fix the isCommentedOut method.

    public static function provideCompileTests(): iterable
    {
        yield 'import_in_multiline_comment' => [
            'input' => <<<EOF
// Asynchronous loading
/**
 *
 * function App() {
 *   return (
 *     <LazyMotion features={() => import('./path/to/domAnimations')}>
 *       <m.div animate={{ scale: 2 }} />
 *     </LazyMotion>
 *   )
 * }
 * ```
 *
 * @public
 */
EOF
            ,
            'expectedJavaScriptImports' => [],
        ];

@tacman
Copy link
Contributor Author

tacman commented Nov 26, 2024

So it turned out to be a change in the asset-mapper recipe to make import strict in development.

@adrianrudnik
Copy link
Contributor

So it turned out to be a change in the asset-mapper recipe to make import strict in development.

The recipe update was the issue for me as well. Configuring this back to warn or ignore helped for now.

@fabpot fabpot closed this as completed in 4fdf3f7 Jan 25, 2025
@zahitrios
Copy link

As @adrianrudnik said, the problem is the asset mapper, I removed this line from composer.json
"symfony/asset-mapper": "7.2.*"

And then I did run composer update

@tacman
Copy link
Contributor Author

tacman commented Apr 24, 2025

No, that's not the right solution, because the application may need asset-mapper. Instead, change

# config/packages/asset_mapper.yaml

framework:
    asset_mapper:
        # The paths to make available to the asset mapper.
        paths:
            - assets/
        missing_import_mode: warn

The problem is that the original recipe had the missing_import_mode set to strict.

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