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

Gatsby 5.4.0 fails to import yaml files #37453

Closed
2 tasks done
pettinarip opened this issue Jan 12, 2023 · 1 comment · Fixed by #37454
Closed
2 tasks done

Gatsby 5.4.0 fails to import yaml files #37453

pettinarip opened this issue Jan 12, 2023 · 1 comment · Fixed by #37454
Assignees
Labels
status: confirmed Issue with steps to reproduce the bug that’s been verified by at least one reviewer. topic: webpack/babel Webpack or babel type: bug An issue or pull request relating to a bug in Gatsby

Comments

@pettinarip
Copy link

Preliminary Checks

Description

Using Gatsby v5, when you try to import a yaml file, you get an error from the yaml-loader.

Reproduction Link

https://github.com/pettinarip/gatsby-5-yaml

Steps to Reproduce

  1. Create a yaml file in the project
  2. Import it from a page component (import yamlFile from './test.yaml')
  3. Run gatsby develop
  4. See error

Expected Result

gatsby-develop runs without any error when you try to import a yaml file

Note: I've tried doing this but it didn't work.

exports.onCreateWebpackConfig = ({ loaders, actions }) => {
  actions.setWebpackConfig({
    module: {
      rules: [
        {
          test: /\.ya?ml$/,
          type: `json`,
          use: [loaders.yaml({ asJSON: true })],
        },
      ],
    },
  })
}

Actual Result

ERROR UNKNOWN

Module parse failed: Unexpected token "e" (0x65) in JSON at position 0 while parsing near "export
default [{id:..."
File was processed with these loaders:

  • ./node_modules/yaml-loader/index.js
  • ./node_modules/yaml-loader/index.js
    You may need an additional loader to handle the result of these loaders.
    JSONParseError: Unexpected token "e" (0x65) in JSON at position 0 while parsing near "export default
    [{id:..."
    at JsonParser.parse (/home/lap/gatsby-yaml/node_modules/webpack/lib/json/JsonParser.js:43:7)
    at /home/lap/gatsby-yaml/node_modules/webpack/lib/NormalModule.js:1087:26
    at processResult (/home/lap/gatsby-yaml/node_modules/webpack/lib/NormalModule.js:800:11)
    at /home/lap/gatsby-yaml/node_modules/webpack/lib/NormalModule.js:860:5
    at /home/lap/gatsby-yaml/node_modules/loader-runner/lib/LoaderRunner.js:407:3
    at iterateNormalLoaders
    (/home/lap/gatsby-yaml/node_modules/loader-runner/lib/LoaderRunner.js:233:10)
    at iterateNormalLoaders
    (/home/lap/gatsby-yaml/node_modules/loader-runner/lib/LoaderRunner.js:240:10)
    at /home/lap/gatsby-yaml/node_modules/loader-runner/lib/LoaderRunner.js:255:3
    at runSyncOrAsync
    (/home/lap/gatsby-yaml/node_modules/loader-runner/lib/LoaderRunner.js:143:11)
    at iterateNormalLoaders
    (/home/lap/gatsby-yaml/node_modules/loader-runner/lib/LoaderRunner.js:251:2)
    at iterateNormalLoaders
    (/home/lap/gatsby-yaml/node_modules/loader-runner/lib/LoaderRunner.js:240:10)
    at /home/lap/gatsby-yaml/node_modules/loader-runner/lib/LoaderRunner.js:255:3
    at runSyncOrAsync
    (/home/lap/gatsby-yaml/node_modules/loader-runner/lib/LoaderRunner.js:143:11)
    at iterateNormalLoaders
    (/home/lap/gatsby-yaml/node_modules/loader-runner/lib/LoaderRunner.js:251:2)
    at /home/lap/gatsby-yaml/node_modules/loader-runner/lib/LoaderRunner.js:224:4
    at /home/lap/gatsby-yaml/node_modules/webpack/lib/NormalModule.js:834:15

ModuleParseError: Module parse failed: Unexpected token "e" (0x65) in JSON at position 0 while parsin
g near "export default [{id:..."
File was processed with these loaders:

  • ./node_modules/yaml-loader/index.js
  • ./node_modules/yaml-loader/index.js
    You may need an additional loader to handle the result of these loaders.
    JSONParseError: Unexpected token "e" (0x65) in JSON at position 0 while parsing near "export default
    [{id:..."

Environment

System:
    OS: Linux 5.13 Ubuntu 21.10 21.10 (Impish Indri)
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Shell: 5.8 - /usr/bin/zsh
  Binaries:
    Node: 18.13.0 - ~/.volta/tools/image/node/18.13.0/bin/node
    Yarn: 1.22.18 - ~/.volta/tools/image/yarn/1.22.18/bin/yarn
    npm: 8.19.3 - ~/.volta/tools/image/node/18.13.0/bin/npm
  Browsers:
    Chrome: 107.0.5304.87
    Firefox: 108.0.2
  npmPackages:
    gatsby: ^5.4.0 => 5.4.0
    gatsby-plugin-image: ^3.4.0 => 3.4.0
    gatsby-plugin-manifest: ^5.4.0 => 5.4.0
    gatsby-plugin-sharp: ^5.4.0 => 5.4.0
    gatsby-source-filesystem: ^5.4.0 => 5.4.0
    gatsby-transformer-sharp: ^5.4.0 => 5.4.0

Config Flags

No response

@pettinarip pettinarip added the type: bug An issue or pull request relating to a bug in Gatsby label Jan 12, 2023
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Jan 12, 2023
@LekoArts LekoArts added status: confirmed Issue with steps to reproduce the bug that’s been verified by at least one reviewer. topic: webpack/babel Webpack or babel and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Jan 12, 2023
@LekoArts LekoArts self-assigned this Jan 12, 2023
@LekoArts LekoArts changed the title Gatsby v5 fails to import yaml files Gatsby 5.4.0 fails to import yaml files Jan 12, 2023
@pieh
Copy link
Contributor

pieh commented Jan 13, 2023

Fix was published in:

  • gatsby@4.25.3
  • gatsby@5.4.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: confirmed Issue with steps to reproduce the bug that’s been verified by at least one reviewer. topic: webpack/babel Webpack or babel type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants