Closed BinToss closed 2 months ago
@BinToss --loadConfigs
only loads packemon specific configs. You would need to customize babel through those.
https://packemon.dev/docs/advanced#customizing-babel-swc-and-rollup
Oh, I misunderstood the requirements, then. I though only one of the conditions were needed and that --loadConfigs
would allow Babel and Rollup to load their config files.
Since I have your attention, should I also create new Issues to report Packemon's Types.ts not being exported or recognized by Typescript? I followed the example on the page you linked, but import type { ConfigFile } from 'packemon';
is invalid. In fact, none of Types.ts's exports are visible.
Could not find a declaration file for module 'packemon'.
'c:/Repos/HaloSPV3/HCE.Shared/node_modules/packemon/mjs/index.mjs' implicitly has an 'any' type.
Try `npm i --save-dev @types/packemon` if it exists or add a new declaration (.d.ts) file containing `declare module 'packemon';`
ts(7016)
That type can be imported via relative path to src/Types.ts, but that file contains syntax errors. All imports in that file are expected to be type
imports, but most are not.
Also in Types.ts is non-type imports of interface types. Typescript does not tolerate this with 'verbatimModuleSyntax'.
node_modules/packemon/src/types.ts:1:10 - error TS1484: 'OutputOptions' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.
1 import { OutputOptions as RollupOutputOptions, RollupOptions } from 'rollup';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/packemon/src/types.ts:1:48 - error TS1484: 'RollupOptions' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.
1 import { OutputOptions as RollupOutputOptions, RollupOptions } from 'rollup';
~~~~~~~~~~~~~
node_modules/packemon/src/types.ts:2:10 - error TS1484: 'TransformOptions' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.
2 import { TransformOptions as BabelOptions } from '@babel/core';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/packemon/src/types.ts:3:10 - error TS1484: 'PackageStructure' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.
3 import { PackageStructure } from '@boost/common';
~~~~~~~~~~~~~~~~
Yeah open up a new issue, those should work.
Should I also open a feature request issue to add the @babel/plugin-syntax-import-attributes
plugin to allow JSON imports with type assertion (import p from "p.json" with {type:"json"}
)? Babel's complaints about needing that plugin is what led to this Issue being opened.
@BinToss Go for it.
Though somewhat unrelated to Packemon, I think you should be aware of this issue in case another user experiences it.
The resolve package affects Rollup's output directory layout unexpectedly.
If any source files import it, the output directory becomes nested. Instead of outputting files to ./mjs
, they're output to ./mjs/src
. Packemon and Typescript are not made aware of this and assume the output directory is unnested. When built with --addExports --declarations
, the generated package.json#exports (and main, types, et cetera) are not aware the MJS files have been nested. Package exports and types will not work at all when this happens.
Expected Layout:
./
|_ mjs/
| |_ *.mjs
| |_ *.map
| |_ *.d.ts
|_ src/
| |_ *.ts
|_ (other root folders/files)
Actual Layout when importing resolve
:
./
|_ mjs/
| |_ _virtual/
| |_ node_modules/
| |_ mjs/
| | |_ *.mjs
| | |_ *.map
| |_ *.d.ts
|_ src/
| |_ *.ts
|_ (other root folders/files)
Is resolve
in the package deps? It should be marked external so this doesn't happen.
Is
resolve
in the package deps?
Not explicitly. I was depending on it as a transitive dependency. That probably contributed to the issue.
It should be marked external so this doesn't happen.
Thank you! I haven't had to mess with rollup's externals configuration before, so your tip was greatly appreciated!
For now, I ended up using JSON import attributes instead of resolve + a dynamic import/require. But, just in case it pops up later, I've changed packemon.config.js#config.rollupInput to conditionally add resolve
to the externals array.
Is this intentional or is it a bug?
Packemon 4.0.1
babel.config.json
package.json
ERROR
C:\Repos\HaloSPV3\HCE.Shared\src\eslintConfig.ts: Support for the experimental syntax 'importAttributes' isn't currently enabled (9:65):
Add @babel/plugin-syntax-import-attributes (https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-import-attributes) to the 'plugins' section of your Babel config to enable parsing.
If you already added the plugin for this syntax to your config, it's possible that your config isn't being loaded. You can re-run Babel with the BABEL_SHOW_CONFIG_FOR environment variable to show the loaded configuration: npx cross-env BABEL_SHOW_CONFIG_FOR=C:\Repos\HaloSPV3\HCE.Shared\src\eslintConfig.ts
See https://babeljs.io/docs/configuration#print-effective-configs for more info.
STACK TRACE