OK I am in the process of setting up codegen, and I’m really struggling with getting the importPath
in my plasmic-init.ts
file to work. Would love some help —either there is a bug in plasmic sync
or I am misunderstanding something basic.
My directory structure looks like this
. (root directory of nextjs project)
|
+ src
| L components
| L common
| L NavBar
| L index.tsx // file containing NavBar module
L components
L all my plasmic files
My plasmic.json
file defines the following srcDir
// plasmic.json
"srcDir": "components",
All my code components that are from other packages are working just fine, e.g. this works great:
// plasmic-init.ts
PLASMIC.registerComponent(Html, {
name: 'EmailHtml',
props: {
children: 'slot',
lang: 'string',
dir: 'string',
},
importPath: '@react-email/html'
});
But when I try to register one of my own components:
// plasmic-init.ts
PLASMIC.registerComponent(NavBar, {
name: 'NavBar',
props: {
leftSide: {
type: 'slot',
defaultValue: []
},
showLink: 'boolean'
},
importPath: '../src/components/common/NavBar'
});
I get a build error when doing npm run build
:
./components/plasmic/osito/PlasmicAbout.tsx
Attempted import error: 'NavBar' is not exported from 'src/components/common/NavBar' (imported as 'NavBar').
Import trace for requested module:
./components/plasmic/osito/PlasmicAbout.tsx
I inspected the Plasmic-generated tsx file to see what was going on, and I found this:
// app/components/plasmic/osito/PlasmicAbout.tsx
import { NavBar } from "src/components/common/NavBar"; // plasmic-import: RaLtnrQhk5/codeComponent
import { Main } from "src/components/common/Main"; // plasmic-import: 2Pfh91dOe9/codeComponent
which is strange because that import path is missing several ..
prefixes. It should be ../../../src/components/common/NavBar
in order for the build to work.
Is there something different I should be putting as my importPath
? I’ve tried everything I can think of but I can’t explain why plasmic sync
is behaving in this way.
Any help would be appreciated. @chungwu