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

Transpilation errors when I try to use DataTable #2457

Closed
tfuda opened this issue Feb 5, 2020 · 2 comments
Closed

Transpilation errors when I try to use DataTable #2457

tfuda opened this issue Feb 5, 2020 · 2 comments

Comments

@tfuda
Copy link

tfuda commented Feb 5, 2020

I'm trying to use the DataTable component within my React/Babel/Webpack project. I'm using Webpack 4 and Babel 7. I've modified my Webpack loaders configuration to include the node_modules/@salesforce/design-system-react package in my build process, and I've updated my .babelrc file as follows:

{
	"presets": [
		"@babel/preset-env",
		"@babel/preset-react"
	],
	"plugins": [
		"@babel/plugin-proposal-object-rest-spread",
		"@babel/plugin-proposal-export-default-from",
		"@babel/plugin-proposal-export-namespace-from",
		[
			"@babel/plugin-proposal-class-properties",
			{
				"loose": true
			}
		]
	]
}

This is in accordance with the recommendation made here for transpiling using Babel 7+: #1621 (comment).

My Webpack loader configuration looks like this:

var path = require('path');
function excludeNodeModulesExcept (modules)
{
	var pathSep = path.sep;
	if (pathSep === '\\') // must be quoted for use in a regexp:
		pathSep = '\\\\';
	var moduleRegExps = modules.map (function (modName) { return new RegExp("node_modules" + pathSep + modName);});
	
	return function (modulePath) {
		if (/node_modules/.test(modulePath)) {
			for (var i = 0; i < moduleRegExps.length; i ++)
				if (moduleRegExps[i].test(modulePath)) return false;
			return true;
		}
		return false;
	};
}

module.exports = [
	{
		test: /\.(js|jsx)$/,
		exclude: excludeNodeModulesExcept(["@salesforce/design-system-react"]),
		use: ["babel-loader", "eslint-loader"]
	},
	{
		test: /\.css$/,
		use: ["style-loader", "css-loader"],
	},
	{
		test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
		use: ["file-loader"]
	},
	{
		test: /\.(woff|woff2|ttf|svg|gif|jpg|png)$/,
		use: [
			{
				loader: "url-loader",
				options: {
					limit: 20000
				}
			}
		]
	},
];

I'm not excluding the node_modules@salesforce/design-system-react directory from the build. When I try to build my app that includes DataTable, I get the following compilation errors in data-table/cell.jsx and data-table/index.jsx:


ERROR in ./node_modules/@salesforce/design-system-react/components/data-table/cell.jsx 22:2
Module parse failed: Unexpected token (22:2)
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
|               : props.children;
|       const contents = (
>               <div
|                       className={classNames({
|                               'slds-truncate': props.fixedLayout,
 @ ./src/components/exchange/exchange-summary.jsx 40:0-87 129:29-42
 @ ./src/components/exchange/exchange.jsx
 @ ./src/index.jsx

ERROR in ./node_modules/@salesforce/design-system-react/components/data-table/index.jsx 70:20
Module parse failed: Unexpected token (70:20)
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
|       // ### Display Name
|       // Always use the canonical component name as the React display name.
>       static displayName = DATA_TABLE;
|
|       // ### Prop Types
 @ ./src/components/exchange/exchange-summary.jsx 39:0-78 103:61-70
 @ ./src/components/exchange/exchange.jsx
 @ ./src/index.jsx
i 「wdm」: Failed to compile.

Any thoughts on what I might be missing here.

@welcome
Copy link

welcome bot commented Feb 5, 2020

Thanks for opening your first issue! 👋
If you have found this library helpful, please star it. A maintainer will try to respond within 7 days. If you haven’t heard anything by then, please bump this thread.

@tfuda
Copy link
Author

tfuda commented Feb 5, 2020

Never mind... I was importing the from the wrong place. I was importing from:

import` DataTable from "@salesforce/design-system-react/components/data-table";

Need to import the compiled modules from:

import` DataTable from "@salesforce/design-system-react/module/components/data-table";

@tfuda tfuda closed this as completed Feb 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant