Closed HarminderSethi closed 7 months ago
It looks like you're missing the new gulpfile modifications that are required to use es2021 JavaScript in your project. https://learn.microsoft.com/en-us/graph/toolkit/get-started/build-a-sharepoint-web-part?tabs=react#configure-webpack
Note that if you development environment is Windows then the function listed there is not quite right due to the strings in litFolders
using Unix path separators and not Windows path separators.
@gavinbarron I followed the same steps provided in the link but was still facing the issue. The issue is fixed after following the steps provided in https://github.com/microsoftgraph/microsoft-graph-toolkit/issues/3055
@HarminderSethi If you are on windows its probably a path issue, I had to change the litFolders variable:
const nodeModulesPath = path.resolve(__dirname, 'node_modules');
const litFolders = [
path.join(nodeModulesPath, 'lit'),
path.join(nodeModulesPath, '@lit'),
path.join(nodeModulesPath, 'lit-html'),
path.join(nodeModulesPath, 'lit-element'),
];
And if you are using spfx-fast-serve you also have to update your webpack.extend.js file in the fast-serve folder:
/*
* User webpack settings file. You can add your own settings here.
* Changes from this file will be merged into the base webpack configuration file.
* This file will not be overwritten by the subsequent spfx-fast-serve calls.
*/
const path = require('path');
// you can add your project related webpack configuration here, it will be merged using webpack-merge module
// i.e. plugins: [new webpack.Plugin()]
const webpackConfig = {
}
// for even more fine-grained control, you can apply custom webpack settings using below function
const transformConfig = function (initialWebpackConfig) {
// Define the paths to include for babel-loader processing
const litFolders = [
path.resolve('node_modules/lit'),
path.resolve('node_modules/@lit'),
path.resolve('node_modules/lit-html'),
path.resolve('node_modules/lit-element'),
];
// Add a rule for processing JS files with babel-loader
initialWebpackConfig.module.rules.push({
test: /\.js$/,
include: resourcePath => litFolders.some(litFolder => resourcePath.includes(litFolder)),
use: {
loader: 'babel-loader',
options: {
plugins: [
'@babel/plugin-transform-optional-chaining',
'@babel/plugin-transform-nullish-coalescing-operator',
'@babel/plugin-transform-logical-assignment-operators'
]
}
}
});
return initialWebpackConfig;
}
module.exports = {
webpackConfig,
transformConfig
}
Describe the bug I am trying to use graph toolkit with SPFx and followed the steps provided in https://learn.microsoft.com/en-us/graph/toolkit/get-started/mgt-spfx but gulp serve is throwing error
Error - [webpack] 'dist': ./node_modules/lit-html/directives/class-map.js 6:106 Module parse failed: Unexpected token (6:106) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders | Copyright 2018 Google LLC | SPDX-License-Identifier: BSD-3-Clause
@ ./node_modules/lit/decorators.js 1:354-415 1:354-415 @ ./node_modules/@microsoft/mgt-element/dist/es6/components/baseProvider.js @ ./node_modules/@microsoft/mgt-element/dist/es6/index.js @ ./lib/webparts/helloWorld/HelloWorldWebPart.js
To Reproduce Steps to reproduce the behavior:
Expected behavior version 4.0.1 should work with SPFx 1.18.x.