As a newcomer to babel and browserify, I encountered an issue while trying to transpile with browserify and babel. After installing the threejs package and adding the following import:
import * as THREE from 'three'
Everything worked fine when transpiled using this command:
browserify input.js > output.js -t babelify
However, when I added another import:
import {GLTFLoader} from '../node_modules/three/examples/jsm/loaders/GLTFLoader'
and ran the same command again, it failed with the error message:
'import' and 'export' may appear only with 'sourceType: module' (1:0)
I tried adding type module in the package.json file, but it did not resolve the issue. Here is my package.json:
{
"name": "three.js",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"three": "^0.129.0"
},
"devDependencies": {
"@babel/core": "^7.14.5",
"@babel/preset-env": "^7.14.5",
"babelify": "^10.0.0"
},
"type": "module"
}
Additionally, here is my babel.config.json:
{
"presets": ["@babel/preset-env"]
}
I am wondering if there are any other adjustments or additions that need to be made?