Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' - Browserify #1419

Closed
StupidIncarnate opened this issue Oct 13, 2017 · 3 comments

Comments

@StupidIncarnate
Copy link

Bug

What MDC-Web Version are you using?

0.22.0

What browser(s) is this bug affecting?

This is happening with browserify / babelify

What OS are you using?

Win 10

What are the steps to reproduce the bug?

I'm using browserify to package my node_modules into a vendor file. It's been working fine until I installed the material-components-web module. After doing that and including it in the packaging, I'm getting the following error:
SyntaxError: 'import' and 'export' may appear only with 'sourceType: module'

What is the expected behavior?

For it to not error on packaging

What is the actual behavior?

Getting the following error: SyntaxError: 'import' and 'export' may appear only with 'sourceType: module'

Any other information you believe would be useful?

I was on material-design-lite previous and it worked with this build process no problem. When I go to switch to material-components-web, that's when I run into this issue.
I tried switching 'material-components-web' to @material/animate but it gives the same error.
I'm using import / export in my app code and this process doesn't choke on that. Seems to be just how the node package is setup.

This is the browserify setup I have to package vendors:

console.log(": Bundle Vendor :", that.getRoot());
var requires = [
    "backbone",
    "bluebird",
    "dialog-polyfill",
    "farbtastic",
    "jquery",
    "jquery.browser",
    "jquery-ui-browserify",
    "handlebars",
    "underscore",
    "underscore.string"
  ]
var bInstance = browserify();

requires.push("material-components-web");

bInstance.require(requires);

bInstance = bInstance.transform("babelify", {
	presets: ["es2015", "es2016", "stage-0"]
});

// console.log("BUILD VENDOR");

fsExtra.ensureFileSync(path.join(parentFolder, "packaged", "static", "vendor.js"));

var fsInstance = fs.createWriteStream(path.join(parentFolder, "packaged", "static", "vendor.js"));
var bundle = bInstance.bundle();
bundle.pipe(fsInstance);

fsInstance.on("finish", function(){
	console.log(":: Finished Bundle Vendor ::");
	resolve();
});
fsInstance.on("error", function(e){
	console.log(e);
	reject(e);
});
@StupidIncarnate
Copy link
Author

Looks like it has to be patched with babelify:
babel/babelify#247

@sassanh
Copy link

sassanh commented Nov 21, 2017

I think this issue should be open. material components should add the babelify patch to their package.json otherwise we have to patch package.json each time something is installed via yarn.

@kfranqueiro
Copy link
Contributor

Maybe somewhat related to #929? material-components-web is ES6, while material-components-web/dist/material-components-web is transpiled.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants