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

Build error UglifyJS (with cross-spawn) #5860

Closed
LekoArts opened this issue Jun 12, 2018 · 3 comments
Closed

Build error UglifyJS (with cross-spawn) #5860

LekoArts opened this issue Jun 12, 2018 · 3 comments
Labels
type: question or discussion Issue discussing or asking a question about Gatsby

Comments

@LekoArts
Copy link
Contributor

Description

I'm using cross-spawn for one of my fields.

I get the error:

 Error: commons-ab523a7593dd80499e4a.js from UglifyJs
  SyntaxError: Unexpected character '`' [./~/cross-spawn/lib/enoent.js:6,0]

Steps to reproduce

Can't provide a sample repo. But I looked at other cases:
https://github.com/gatsbyjs/gatsby/issues?utf8=%E2%9C%93&q=uglifyjs

Expected result

Build should finish successfully.

Actual result

Error above.

Environment

System:
OS: Windows 10
CPU: x64 Intel(R) Xeon(R) CPU E3-1230 v3 @ 3.30GHz
Binaries:
Yarn: 1.7.0 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 5.10.0 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: 42.17134.1.0
npmPackages:
gatsby: ^1.9.270 => 1.9.270
gatsby-image: ^1.0.52 => 1.0.52
gatsby-link: ^1.6.44 => 1.6.44
gatsby-plugin-catch-links: ^1.0.22 => 1.0.22
gatsby-plugin-emotion: ^1.1.17 => 1.1.17
gatsby-plugin-lodash: ^1.0.11 => 1.0.11
gatsby-plugin-manifest: ^1.0.25 => 1.0.25
gatsby-plugin-netlify: ^1.0.21 => 1.0.21
gatsby-plugin-offline: ^1.0.18 => 1.0.18
gatsby-plugin-react-helmet: ^2.0.11 => 2.0.11
gatsby-plugin-react-next: ^1.0.11 => 1.0.11
gatsby-plugin-sharp: ^1.6.47 => 1.6.47
gatsby-plugin-sitemap: ^1.2.25 => 1.2.25
gatsby-plugin-typography: ^1.7.18 => 1.7.18
gatsby-remark-autolink-headers: ^1.4.18 => 1.4.18
gatsby-remark-design-system: ^1.0.9 => 1.0.9
gatsby-remark-external-links: ^0.0.4 => 0.0.4
gatsby-remark-prismjs: ^2.0.3 => 2.0.3
gatsby-source-filesystem: ^1.5.38 => 1.5.38
gatsby-transformer-remark: ^1.7.42 => 1.7.42
gatsby-transformer-sharp: ^1.6.26 => 1.6.26

File contents (if changed)

gatsby-node

const path = require('path');
const { createFilePath } = require('gatsby-source-filesystem');
const { toTitleCase, getLastUpdatedTimestamp } = require('./src/utilities');

const getSlugParents = slug => {
  const slugParentString = slug.substring(1, slug.length - 1);
  return slugParentString.split('/');
};

exports.onCreateNode = ({ node, getNode, boundActionCreators }) => {
  const { createNodeField } = boundActionCreators;

  if (node.internal.type === 'MarkdownRemark') {
    const slug = createFilePath({ node, getNode, basePath: 'pages' });
    const slugParentsArr = getSlugParents(slug);

    createNodeField({
      node,
      name: 'slug',
      value: slug,
    });

    createNodeField({
      node,
      name: 'topLevelDir',
      value: toTitleCase(slugParentsArr[0]),
    });

    createNodeField({
      node,
      name: 'subDir',
      value: toTitleCase(slugParentsArr.length > 2 ? slugParentsArr[1] : ''),
    });
  }
};

exports.createPages = ({ graphql, boundActionCreators }) => {
  const { createPage } = boundActionCreators;

  return new Promise((resolve, reject) => {
    const docPage = path.resolve('src/templates/doc.jsx');
    resolve(
      graphql(`
        {
          docs: allMarkdownRemark {
            edges {
              node {
                fileAbsolutePath
                fields {
                  slug
                  topLevelDir
                  subDir
                }
                frontmatter {
                  title
                }
              }
            }
          }
        }
      `).then(result => {
        if (result.errors) {
          console.log(result.errors);
          reject(result.errors);
        }

        const docsList = result.data.docs.edges;

        docsList.forEach(project => {
          createPage({
            path: project.node.fields.slug,
            component: docPage,
            context: {
              slug: project.node.fields.slug,
              topLevelDir: project.node.fields.topLevelDir,
              subDir: project.node.fields.subDir,
              lastUpdated: getLastUpdatedTimestamp(project.node.fileAbsolutePath),
            },
          });
        });
      })
    );
  });
};

exports.modifyWebpackConfig = ({ config, stage }) => {
  config.merge({
    node: { fs: 'empty', child_process: 'empty' },
    resolve: {
      root: path.resolve(config._config.context, 'src'),
    },
  });

  return config;
};

getLastUpdatedTimestamp:

const spawn = require('cross-spawn');

exports.getLastUpdatedTimestamp = filepath =>
  parseInt(spawn.sync('git', ['log', '-1', '--format=%ct', filepath]).stdout.toString('utf-8'), 10) * 1000;
@m-allanson m-allanson added the type: question or discussion Issue discussing or asking a question about Gatsby label Jun 13, 2018
@m-allanson
Copy link
Contributor

Is this another instance of #3780?

@LekoArts
Copy link
Contributor Author

@m-allanson Maybe... But isn't the mentioned line es5?
https://github.com/moxystudio/node-cross-spawn/blob/master/lib/enoent.js

Follow-up question: Are the changes mentioned by Kyle in the linked issue implemented?

@LekoArts
Copy link
Contributor Author

Since Gatsby v2 solves all my issues with that I'm closing this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question or discussion Issue discussing or asking a question about Gatsby
Projects
None yet
Development

No branches or pull requests

2 participants