I'm trying out Javascript support in pants v2.17.0...
# general
s
I'm trying out Javascript support in pants v2.17.0 and am getting errors like
Copy code
22:22:15.40 [INFO] Completed: Parsing imports for workflows-explorer/src/frontend/main.js.
22:22:15.40 [WARN] Javascript source import parser failed for 'workflows-explorer/src/frontend/main.js'. This is most likely due to an unrecoverable syntax error, such as redefining module imports.
22:22:15.40 [WARN] SyntaxError: This experimental syntax requires enabling one of the following parser plugin(s): "jsx", "flow", "typescript". (5:16)
    at instantiate (/tmp/pants-sandbox-GZSaHJ/node_modules/@babel/parser/lib/index.js:64:32)
    at constructor (/tmp/pants-sandbox-GZSaHJ/node_modules/@babel/parser/lib/index.js:364:12)
    at Parser.raise (/tmp/pants-sandbox-GZSaHJ/node_modules/@babel/parser/lib/index.js:3253:19)
    at Parser.expectOnePlugin (/tmp/pants-sandbox-GZSaHJ/node_modules/@babel/parser/lib/index.js:3299:18)
    at Parser.parseExprAtom (/tmp/pants-sandbox-GZSaHJ/node_modules/@babel/parser/lib/index.js:11209:18)
    at Parser.parseExprSubscripts (/tmp/pants-sandbox-GZSaHJ/node_modules/@babel/parser/lib/index.js:10859:23)
    at Parser.parseUpdate (/tmp/pants-sandbox-GZSaHJ/node_modules/@babel/parser/lib/index.js:10842:21)
    at Parser.parseMaybeUnary (/tmp/pants-sandbox-GZSaHJ/node_modules/@babel/parser/lib/index.js:10818:23)
    at Parser.parseMaybeUnaryOrPrivate (/tmp/pants-sandbox-GZSaHJ/node_modules/@babel/parser/lib/index.js:10656:61)
    at Parser.parseExprOps (/tmp/pants-sandbox-GZSaHJ/node_modules/@babel/parser/lib/index.js:10661:23) {
  code: 'BABEL_PARSER_SYNTAX_ERROR',
  reasonCode: 'MissingOneOfPlugins',
  loc: Position { line: 5, column: 16, index: 103 },
  pos: [Getter/Setter],
  missingPlugin: [Getter/Setter]
}
when I try to package. Can I configure pants so I can use "import" statements rather than things like
const dep = require("./dep.js");
?*
So I guess step one is to use
"type": "module"
in my
package.json
?
I've updated all of files to
mjs
as well as
cjs
. If I run webpack outside of pants it apepars to work.
This error appears to be pants being unable to parse ES6 imports?
Not sure what I did but now I keep getting
ENOENT: no such file or directory, open '/tmp/pants-sandbox-AB3lOZ/package.json
(even after stashing all my changes and going back to a known working point)
This one is especially surprising because why would it be there? It should be (and is) in
/tmp/pants-sandbox-AB3lOZ/workflows-explorer/
fwiw
Copy code
package_json(
    name="package_json",
    source="package.json",
    scripts=[
        node_build_script(
            entry_point="build",
            output_directories=["artifacts"],
        )
    ],
    dependencies=[
        ":webpack_config",
    ],
)
is in
workflows-exlporer/BUILD
If I move that to the root directory and do
Copy code
package_json(
    name="package_json",
    source="package.json",
    scripts=[
        node_build_script(
            entry_point="build",
            output_directories=["workflows-explorer/artifacts/"],
        )
    ],
    dependencies=[
        "workflows-explorer:webpack_config",
    ],
)
I can see
/tmp/pants-sandbox-VbV7N6/workflows-explorer/artifacts/
is populated but nothing is written to
dist
I, being a dummy, was running
pants run :package_json
and not
pants package :package_json
.
Okay I think I have this working!
🎉 1
h
JS support is still experimental, so thanks for experimenting!
f
thanks for giving it a try! We also have https://github.com/pantsbuild/example-javascript you can use as a sandbox 🙂