sofn-xyz / mailing

Build, test, send emails with React
https://www.mailing.run
MIT License
3.61k stars 74 forks source link

Monorepo "Could not resolve" errors @0.7.3 #168

Closed alexisveryreal closed 2 years ago

alexisveryreal commented 2 years ago

Hello y'all! I wanted to start using this package unfortunately as soon as I ran npx mailing I received a lot of could not resolve errors

Quick Information

What Happened?

mailing added mailing.config.json to your project with the following contents: { "typescript": true, "emailsDir": "./emails", "outDir": "./previews_html" }

mailing generated your emails dir at ./emails: emails ├── TextEmail.tsx ├── Welcome.tsx ├── components │ ├── BulletedList.tsx │ ├── ButtonPrimary.tsx │ ├── Footer.tsx │ ├── Head.tsx │ ├── Header.tsx │ └── theme.ts ├── index.ts └── previews ├── TextEmail.tsx └── Welcome.tsx √ enter your email for occasional updates about mailing (optional) ... mailing ok, no problem mailing starting preview server mailing adding .gitignore ✘ [ERROR] Could not resolve "....emails"

.mailing/src/moduleManifest.ts:2:21:
  2 │ import sendMail from "..\..\emails";
    ╵                      ~~~~~~~~~~~~~~

You can mark the path "....emails" as external to exclude it from the bundle, which will remove this error.

✘ [ERROR] Could not resolve "....emails/TextEmail"

.mailing/src/moduleManifest.ts:3:22:
  3 │ import TextEmail from "..\..\emails/TextEmail";
    ╵                       ~~~~~~~~~~~~~~~~~~~~~~~~

You can mark the path "....emails/TextEmail" as external to exclude it from the bundle, which will remove this error.

✘ [ERROR] Could not resolve "....emails/Welcome"

.mailing/src/moduleManifest.ts:4:20:
  4 │ import Welcome from "..\..\emails/Welcome";
    ╵                     ~~~~~~~~~~~~~~~~~~~~~~

You can mark the path "....emails/Welcome" as external to exclude it from the bundle, which will remove this error.

✘ [ERROR] Could not resolve "....emails/previews/TextEmail"

.mailing/src/moduleManifest.ts:5:34:
  5 │ import * as TextEmailPreview from "..\..\emails/previews/TextEmail";
    ╵                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

You can mark the path "....emails/previews/TextEmail" as external to exclude it from the bundle, which will remove this error.

✘ [ERROR] Could not resolve "....emails/previews/Welcome"

.mailing/src/moduleManifest.ts:6:32:
  6 │ import * as WelcomePreview from "..\..\emails/previews/Welcome";
    ╵                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

You can mark the path "....emails/previews/Welcome" as external to exclude it from the bundle, which will remove this error.

G:\dev\d-mls-app\node_modules\esbuild\lib\main.js:1624 let error = new Error(${text}${summary}); ^

Error: Build failed with 5 errors: .mailing/src/moduleManifest.ts:2:21: ERROR: Could not resolve "....emails" .mailing/src/moduleManifest.ts:3:22: ERROR: Could not resolve "....emails/TextEmail" .mailing/src/moduleManifest.ts:4:20: ERROR: Could not resolve "....emails/Welcome" .mailing/src/moduleManifest.ts:5:34: ERROR: Could not resolve "....emails/previews/TextEmail" .mailing/src/moduleManifest.ts:6:32: ERROR: Could not resolve "....emails/previews/Welcome" at failureErrorWithLog (G:\dev\d-mls-app\node_modules\esbuild\lib\main.js:1624:15) at G:\dev\d-mls-app\node_modules\esbuild\lib\main.js:1266:28 at runOnEndCallbacks (G:\dev\d-mls-app\node_modules\esbuild\lib\main.js:1179:65) at buildResponseToResult (G:\dev\d-mls-app\node_modules\esbuild\lib\main.js:1264:7) at G:\dev\d-mls-app\node_modules\esbuild\lib\main.js:1377:14 at G:\dev\d-mls-app\node_modules\esbuild\lib\main.js:678:9 at handleIncomingPacket (G:\dev\d-mls-app\node_modules\esbuild\lib\main.js:775:9) at Socket.readFromStdout (G:\dev\d-mls-app\node_modules\esbuild\lib\main.js:644:7) at Socket.emit (node:events:526:28) at addChunk (node:internal/streams/readable:315:12) { errors: [ { detail: undefined, id: '', location: { column: 21, file: '.mailing/src/moduleManifest.ts', length: 14, line: 2, lineText: 'import sendMail from "..\..\emails";', namespace: '', suggestion: '' }, notes: [ { location: null, text: 'You can mark the path "....emails" as external to exclude it from the bundle, which will remove this error.' } ], pluginName: '', text: 'Could not resolve "....emails"' }, { detail: undefined, id: '', location: { column: 22, file: '.mailing/src/moduleManifest.ts', length: 24, line: 3, lineText: 'import TextEmail from "..\..\emails/TextEmail";', namespace: '', suggestion: '' }, notes: [ { location: null, text: 'You can mark the path "....emails/TextEmail" as external to exclude it from the bundle, which will remove this error.' } ], pluginName: '', text: 'Could not resolve "....emails/TextEmail"' }, { detail: undefined, id: '', location: { column: 20, file: '.mailing/src/moduleManifest.ts', length: 22, line: 4, lineText: 'import Welcome from "..\..\emails/Welcome";', namespace: '', suggestion: '' }, notes: [ { location: null, text: 'You can mark the path "....emails/Welcome" as external to exclude it from the bundle, which will remove this error.' } ], pluginName: '', text: 'Could not resolve "....emails/Welcome"' }, { detail: undefined, id: '', location: { column: 34, file: '.mailing/src/moduleManifest.ts', length: 33, line: 5, lineText: 'import as TextEmailPreview from "..\..\emails/previews/TextEmail";', namespace: '', suggestion: '' }, notes: [ { location: null, text: 'You can mark the path "....emails/previews/TextEmail" as external to exclude it from the bundle, which will remove this error.' } ], pluginName: '', text: 'Could not resolve "....emails/previews/TextEmail"' }, { detail: undefined, id: '', location: { column: 32, file: '.mailing/src/moduleManifest.ts', length: 31, line: 6, lineText: 'import as WelcomePreview from "..\..\emails/previews/Welcome";', namespace: '', suggestion: '' }, notes: [ { location: null, text: 'You can mark the path "....emails/previews/Welcome" as external to exclude it from the bundle, which will remove this error.' } ], pluginName: '', text: 'Could not resolve "....emails/previews/Welcome"' } ], warnings: [] }

- I went to check the `moduleManifest.ts` file in the `.mailing/src/moduleManifest.ts`  and saw the following
```typescript
import config from "../../mailing.config.json";
import sendMail from "..\..\emails";
import TextEmail from "..\..\emails/TextEmail";
import Welcome from "..\..\emails/Welcome";
import * as TextEmailPreview from "..\..\emails/previews/TextEmail";
import * as WelcomePreview from "..\..\emails/previews/Welcome";

const previews = { TextEmail: TextEmailPreview, Welcome: WelcomePreview };
const templates = { TextEmail, Welcome };

export { sendMail, config, templates, previews };
const moduleManifest = { sendMail, templates, previews };
export default moduleManifest;

With red typescript errors on the paths with the following typescript error

Cannot find module '....emails' or its corresponding type declarations.ts(2307)

Expected result

Steps to reproduce

# Install a turborepo from scratch
npx create-turbo@latest

# Chose a dir
 Where would you like to create your turborepo? ./mailing-test
# choose npm
? Which package manager do you want to use? npm

# CD into the web app
cd mailing-test/apps/web

# add new dependencies
npm i mailing mailing-core

#run mailing cli
npx mailing

# errors appear :(
✘ [ERROR] Could not resolve "....emails"

    .mailing/src/moduleManifest.ts:2:21:
      2 │ import sendMail from "..\..\emails";

Screenshots

image

Please let me know if you need anything else!

psugihara commented 2 years ago

Thanks for reporting. Something definitely looks funky with those forward slashes in the import path -- never seen anything like that. I'll run through your repro steps later today and see what I find.

psugihara commented 2 years ago

Hey @alexisveryreal, unfortunately I think this is an issue with the Windows paths. Running through the repro steps on linux/mac-os works fine.

We don't have a plan to add Windows support ourselves, but would happily support and merge a community PR if you or another Windows user can get it working.

I added an issue here to track windows support: #172

alexfarrill commented 2 years ago

@alexisveryreal would you give version 0.7.6-next.0 a try and let us know if it fixes your problem? I invoked normalize when generating those paths and I think that might do the trick. Thanks!

alexisveryreal commented 2 years ago

Hey @alexfarrill I get the following now with 0.7.6-next.0

node:child_process:828
    err = new Error(msg);
          ^

Error: Command failed: npm -g root

then later down I get

at checkExecSyncError (node:child_process:828:11)
    at Object.execSync (node:child_process:902:15)
    at _callee4$ (G:\dev\mailing-next-test\node_modules\mailing\dist\mailing.cjs.dev.js:1224:56)
    at tryCatch (G:\dev\mailing-next-test\node_modules\mailing\dist\mailing.cjs.dev.js:141:17)
    at Generator._invoke (G:\dev\mailing-next-test\node_modules\mailing\dist\mailing.cjs.dev.js:121:24)
    at Generator.next (G:\dev\mailing-next-test\node_modules\mailing\dist\mailing.cjs.dev.js:172:21)
    at asyncGeneratorStep (G:\dev\mailing-next-test\node_modules\mailing\dist\mailing.cjs.dev.js:405:24)
    at _next (G:\dev\mailing-next-test\node_modules\mailing\dist\mailing.cjs.dev.js:427:9)
    at G:\dev\mailing-next-test\node_modules\mailing\dist\mailing.cjs.dev.js:434:7
    at new Promise (<anonymous>) {
  status: 1,
  signal: null,
  output: [
    null,
    Buffer(0) [Uint8Array] [],
    Buffer(408) [Uint8Array] [
      110, 112, 109,  32,  69,  82,  82,  33,  32,  87, 111, 114,
      107, 115, 112,  97,  99, 101, 115,  32, 110, 111, 116,  32,
      115, 117, 112, 112, 111, 114, 116, 101, 100,  32, 102, 111,
      114,  32, 103, 108, 111,  98,  97, 108,  32, 112,  97,  99,
      107,  97, 103, 101, 115,  10,  10, 110, 112, 109,  32,  69,
       82,  82,  33,  32,  65,  32,  99, 111, 109, 112, 108, 101,
      116, 101,  32, 108, 111, 103,  32, 111, 102,  32, 116, 104,
      105, 115,  32, 114, 117, 110,  32,  99,  97, 110,  32,  98,
      101,  32, 102, 111,
      ... 308 more items
    ]
  ],
  pid: 640,
  stdout: Buffer(0) [Uint8Array] [],
  stderr: Buffer(408) [Uint8Array] [
    110, 112, 109,  32,  69,  82,  82,  33,  32,  87, 111, 114,
    107, 115, 112,  97,  99, 101, 115,  32, 110, 111, 116,  32,
    115, 117, 112, 112, 111, 114, 116, 101, 100,  32, 102, 111,
    114,  32, 103, 108, 111,  98,  97, 108,  32, 112,  97,  99,
    107,  97, 103, 101, 115,  10,  10, 110, 112, 109,  32,  69,
     82,  82,  33,  32,  65,  32,  99, 111, 109, 112, 108, 101,
    116, 101,  32, 108, 111, 103,  32, 111, 102,  32, 116, 104,
    105, 115,  32, 114, 117, 110,  32,  99,  97, 110,  32,  98,
    101,  32, 102, 111,
    ... 308 more items
  ]
}

When checking the moduleManifest.ts file it still has the incorrect/weird paths slashes as well

Thank you for trying though!

psugihara commented 2 years ago

Oddly I'm seeing something similar when I merged main into my ui branch. main is working fine for me and so is the ui branch but something with the merge... 🕵️

➜  mailing git:(145-immersion-ui-scaffold-page-layout) yarn dev
yarn run v1.22.18
$ cd packages/cli && rm -rf .mailing && src/dev.js
npm ERR! Workspaces not supported for global packages

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/petersugihara/.npm/_logs/2022-09-09T03_12_59_523Z-debug-0.log
node:child_process:828
    err = new Error(msg);
          ^

Error: Command failed: npm -g root
npm ERR! Workspaces not supported for global packages
alexfarrill commented 2 years ago

@alexisveryreal would you try 0.7.7-next.0 ? I think that error you posted is thrown before the lines that I changed so would like to see what the output is. Thanks!

@psugihara you can try 0.7.7-next.0 too, I think we should prob release this one since exec'ing npm -g root seems not to work sometimes

psugihara commented 2 years ago

yep, trying now. this fixed in my branch.

It was happening in my branch because you can't call that command or use global packages from inside of the yarn workspace:

Screen Shot 2022-09-08 at 8 47 40 PM
psugihara commented 2 years ago

@alexfarrill your release works in my turborepo project where I repro'd the npm -g root error. Let's ship it.

alexfarrill commented 2 years ago

yeah, it just removes the npm -g root altogether. you would only need that if your project were using some packages that are installed globally, which i think is probably atypically, so maybe we were overthinking it. we could add it back in with more refinement if someone raises that problem. for now let's ship it tho, will do

alexfarrill commented 2 years ago

if you want to add some detail on how to setup turborepo to #178 that one should be easy to implement

alexisveryreal commented 2 years ago

@alexfarrill No more npm -g root error, but paths errors are still there. This time though they are all the same type of slash at least.

So 0.7.3 import TextEmail from "..\..\emails/TextEmail"; image

0.7.7-next-0 import TextEmail from "..\..\emails\TextEmail"; image

alexfarrill commented 2 years ago

Thanks @alexisveryreal ! That looks like what I was expecting to see, since the normalize docs says: "Since Windows recognizes multiple path separators, both separators will be replaced by instances of the Windows preferred separator (\):" But I did think that would have solved the problem for you, I will have to go back and look at your error again to read it in more detail

alexfarrill commented 2 years ago
✘ [ERROR] Could not resolve "....emails"

    .mailing/src/moduleManifest.ts:2:21:
      2 │ import sendMail from "..\..\emails";
        ╵                      ~~~~~~~~~~~~~~

  You can mark the path "....emails" as external to exclude it from the bundle, which will remove
  this error.

It looks almost like it is interpreting the backslash as a character escape on the . character since "..\..\" ends up being interpreted as "....". When you are developing, are you using backslashes or forward slashes? Is one preferred or do both typically work for things like imports?

alexfarrill commented 2 years ago

From the screenshot it even looks like your editor is doing that with highlighting each character. Hmm, maybe if you can confirm that forward slash works for Windows there is a way we can just force it to use /

alexfarrill commented 2 years ago

@alexisveryreal try mailing@0.7.7-next.1

alexfarrill commented 2 years ago

I am guessing that / is fine in your env since that first import statement has no problem. mailing@0.7.7-next.1 forces it to posix

alexisveryreal commented 2 years ago

Yup! Forward slashes definitely work on windows as that is what i'm used to using.

So for example importing would look like this for me

import {
 ComponentA,
 ComponentB,
} from '../components/common'

Will try the new version now though!

alexisveryreal commented 2 years ago

No more paths error woo!

However, when starting the server it seems to kaboom. Here is the full error.

    ███╗   ███╗ █████╗ ██╗██╗     ██╗███╗   ██╗ ██████╗
    ████╗ ████║██╔══██╗██║██║     ██║████╗  ██║██╔════╝
    ██╔████╔██║███████║██║██║     ██║██╔██╗ ██║██║  ███╗
    ██║╚██╔╝██║██╔══██║██║██║     ██║██║╚██╗██║██║   ██║
    ██║ ╚═╝ ██║██║  ██║██║███████╗██║██║ ╚████║╚██████╔╝
    ╚═╝     ╚═╝╚═╝  ╚═╝╚═╝╚══════╝╚═╝╚═╝  ╚═══╝ ╚═════╝

mailing added mailing.config.json in your project with the following contents:
{
  "typescript": true,
  "emailsDir": "./emails",
  "outDir": "./previews_html",
  "anonymousId": "92256fab-f9f0-450b-aed2-becbc9c7548b"
}

mailing mailing collects anonymous telemetry data about usage
mailing generated your emails dir at ./emails:
emails
├── TextEmail.tsx
├── Welcome.tsx
├── components
│   ├── BulletedList.tsx
│   ├── ButtonPrimary.tsx
│   ├── Footer.tsx
│   ├── Head.tsx
│   ├── Header.tsx
│   └── theme.ts
├── index.ts
└── previews
    ├── TextEmail.tsx
    └── Welcome.tsx
√ enter your email for occasional updates about mailing (optional) ...
mailing ok, no problem
mailing starting preview server
mailing adding .gitignore
event - compiled client and server successfully in 20.1s (183 modules)
wait  - compiling...
event - compiled client and server successfully in 145 ms (183 modules)
mailing watching for changes to emails
mailing running preview at http://localhost:3883/
error - uncaughtException: Error: spawn undefined\System32\WindowsPowerShell\v1.0\powershell ENOENT
    at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:478:16)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'spawn undefined\\System32\\WindowsPowerShell\\v1.0\\powershell',
  path: 'undefined\\System32\\WindowsPowerShell\\v1.0\\powershell',
  spawnargs: [
    '-NoProfile',
    '-NonInteractive',
    '–ExecutionPolicy',
    'Bypass',
    '-EncodedCommand',
    'UwB0AGEAcgB0ACAAIgBoAHQAdABwADoALwAvAGwAbwBjAGEAbABoAG8AcwB0ADoAMwA4ADgAMwAvACIA'
  ]
}

Very weird 🤔

alexfarrill commented 2 years ago

Well, glad the slashes are now correct... not sure what that spawn error is tho unfort

nickfrosty commented 1 year ago

I know this issue is pasted closed, but to help people in the future with this similar spawn issue:

Seems like the spawn error shown above has something to do with how powershell handles child processes. This is a stackoverflow question about it.

In a nutshell, you can run the commands using WSL or the "Git Bash" terminal that VS code supports.