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

Attempting to add a loader results in TypeError: Cannot read property 'push' of undefined #927

Closed
1 of 4 tasks
tgorgdotcom opened this issue Oct 12, 2017 · 3 comments · Fixed by #929
Closed
1 of 4 tasks

Comments

@tgorgdotcom
Copy link

tgorgdotcom commented Oct 12, 2017

Category

  • Question
  • Typo
  • Bug
  • Additional article idea

Expected or Desired Behavior

Adding a loader for .woff2 files to the Sharepoint Framework webpack config

Observed Behavior

Error occurs when running gulp serve:

 TypeError: Cannot read property 'push' of undefined
    at Object.additionalConfiguration (/Volumes/tgorg/Work/peach/ProjectPeach/gulpfile.js:8:40)
    at ConfigureWebpackTask.executeTask (/Volumes/tgorg/Work/peach/ProjectPeach/node_modules/@microsoft/sp-build-core-tasks/lib/configureWebpack/ConfigureWebpackTask.js:432:38)
    at /Volumes/tgorg/Work/peach/ProjectPeach/node_modules/@microsoft/gulp-core-build/lib/tasks/GulpTask.js:179:32
    at ConfigureWebpackTask.GulpTask.execute (/Volumes/tgorg/Work/peach/ProjectPeach/node_modules/@microsoft/gulp-core-build/lib/tasks/GulpTask.js:171:16)
    at _executeTask (/Volumes/tgorg/Work/peach/ProjectPeach/node_modules/@microsoft/gulp-core-build/lib/index.js:363:42)
    at /Volumes/tgorg/Work/peach/ProjectPeach/node_modules/@microsoft/gulp-core-build/lib/index.js:264:59
    at process._tickCallback (internal/process/next_tick.js:103:7)

Steps to Reproduce

Added the following code to gulpfile.js right before build.initialize(gulp);

build.configureWebpack.mergeConfig({
	additionalConfiguration: (generatedConfiguration) => {
		generatedConfiguration.module.loaders.push([
			{ test: /\.woff2(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "url-loader" }
		]);
		return generatedConfiguration;
	}
});

@iclanton
Copy link
Contributor

This is actually a documentation bug around the way we describe how to extend the Webpack config - thanks for pointing it out. We noticed this a few days ago and should have updated documentation out soon.

The issue is that the documentation describes how to extend the Webpack v1 config and the config format changed between Webpack v1 and v2, but we didn't update the documentation when we released tools with Webpack v2. If you're curious, here's a summary of the changes between the two config formats.

For your case, this code should work:

build.configureWebpack.mergeConfig({
  additionalConfiguration: (generatedConfiguration) => {
    generatedConfiguration.module.rules.push(
      {
        test: /\.woff2(\?v=[0-9]\.[0-9]\.[0-9])?$/,
        use: {
          loader: 'url-loader'
        }
      }
    );

    return generatedConfiguration;
  }
});

@tgorgdotcom
Copy link
Author

Ah! Excellent. This is working for me now. Thank you very much for your reply.

@msft-github-bot
Copy link
Collaborator

Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues

@SharePoint SharePoint locked as resolved and limited conversation to collaborators Jan 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants