Can I reference a module as the path for a NextjsS...
# help
l
Can I reference a module as the path for a NextjsSite I want to deploy with sst? Currently I get an error on the below code (
The system cannot find the path specified.
), perhaps because node_modules is not recognized as a directory due to being in .gitignore. Possible I am making a basic mistake. My use case is: • Want to deploy a NextjsSite from a separate repository, which I have installed into
node_modules
• That'll let me be able to develop the separate repository cleanly - I'll update it when I need to - instead of having to have the whole source code for my Next.js app inside the
sst
project
Copy code
import * as sst from "@serverless-stack/resources";

export default class MyStack extends sst.Stack {
  constructor(scope, id, props) {
    super(scope, id, props);

    // Create a Next.js site
    const site = new sst.NextjsSite(this, "cloakist-notion-nextjs", {
      path: "node_modules/cloakist-notion-nextjs",
      environment: {
        // Pass the table details to our app
        REGION: scope.region,
      },
    });

    // Show the site URL in the output
    this.addOutputs({
      URL: site.url,
    });
  }
}
t
Interesting approach. I'll let @Frank chime in as he's more familiar with our static sites. We typically recommend monorepo structures until boundaries can be very explicitly defined
f
@Louis Barclay does the
node_modules/cloakist-notion-nextjs
directory exist?
Also can you share the full output from leading up to the
The system cannot find the path specified.
error?
l
Yes it does
View of my file structure
View of cloakist-notion-nextjs folder which is within node_modules
f
@Louis Barclay Thanks for the details!
If you go into
node_modules/@serverless-stack/resources/dist
, open up
NextjsSite.js
, and look for the
buildApp()
function.
Try console log
cmd
and
sitePath
. And we can try running the command in the terminal and see if we get the same result.
l
I get this:
Copy code
Using stage: dev
Preparing your SST app
Transpiling source
Linting source
sitePath: node_modules/cloakist-notion-nextjs
cmd: node C:\Users\louis\Documents\Dev\Cloakist\cloakist-sotion\node_modules\@serverless-stack\resources\assets\NextjsSite\build.js --path C:\Users\louis\Documents\Dev\Cloakist\cloakist-sotion\node_modules\cloakist-notion-nextjs --output C:\Users\louis\Documents\Dev\Cloakist\cloakist-sotion\.build\node_modules-cloakist-notion-nextjs-1635897945421 --config eyJjd2QiOiJDOlxcVXNlcnNcXGxvdWlzXFxEb2N1bWVudHNcXERldlxcQ2xvYWtpc3RcXGNsb2FraXN0LXNvdGlvblxcbm9kZV9tb2R1bGVzXFxjbG9ha2lzdC1ub3Rpb24tbmV4dGpzIiwiYXJncyI6WyJidWlsZCJdfQ==
Building Next.js site node_modules/cloakist-notion-nextjs
The system cannot find the path specified.
(node:28336) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), 
or Buffer.from() methods instead.
(Use `node --trace-deprecation ...` to show where the warning was created)

Error: There was a problem building the "cloakist-notion-nextjs" NextjsSite.
So it passes the
!fs.existsSync(sitePath)
test. The error message 'The system cannot find the path specified.' is not coming from this file, not sure where it's coming from
I wonder if it's some weirdness from me using Windows
This appears to be where it's breaking
I get 'reaches here' log but not the ones after:
Copy code
Using stage: dev
Preparing your SST app
Transpiling source
Linting source
reaches here
sitePath: node_modules/cloakist-notion-nextjs
cmd: node C:\Users\louis\Documents\Dev\Cloakist\cloakist-sotion\node_modules\@serverless-stack\resources\assets\NextjsSite\build.js --path C:\Users\louis\Documents\Dev\Cloakist\cloakist-sotion\node_modules\cloakist-notion-nextjs --output C:\Users\louis\Documents\Dev\Cloakist\cloakist-sotion\.build\node_modules-cloakist-notion-nextjs-1635898345162 --config eyJjd2QiOiJDOlxcVXNlcnNcXGxvdWlzXFxEb2N1bWVudHNcXERldlxcQ2xvYWtpc3RcXGNsb2FraXN0LXNvdGlvblxcbm9kZV9tb2R1bGVzXFxjbG9ha2lzdC1ub3Rpb24tbmV4dGpzIiwiYXJncyI6WyJidWlsZCJdfQ==
Building Next.js site node_modules/cloakist-notion-nextjs
The system cannot find the path specified.
(node:412) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
(Use `node --trace-deprecation ...` to show where the warning was created)

Error: There was a problem building the "cloakist-notion-nextjs" NextjsSite.
Actually sorry, that's not true. It's breaking within buildApp here, as evidenced by the error message and the fact that the logs for sitePath and cmd work just before these lines:
Ah, so now I see that 'cmd' should in theory work in terminal, i.e. running this:
Copy code
node C:\Users\louis\Documents\Dev\Cloakist\cloakist-sotion\node_modules\@serverless-stack\resources\assets\NextjsSite\build.js --path C:\Users\louis\Documents\Dev\Cloakist\cloakist-sotion\node_modules\cloakist-notion-nextjs --output C:\Users\louis\Documents\Dev\Cloakist\cloakist-sotion\.build\node_modules-cloakist-notion-nextjs-1635898523183 --config eyJjd2QiOiJDOlxcVXNlcnNcXGxvdWlzXFxEb2N1bWVudHNcXERldlxcQ2xvYWtpc3RcXGNsb2FraXN0LXNvdGlvblxcbm9kZV9tb2R1bGVzXFxjbG9ha2lzdC1ub3Rpb24tbmV4dGpzIiwiYXJncyI6WyJidWlsZCJdfQ==
I get the same error -
The system cannot find the path specified.
So I'm thinking this is a Windows thing
Maybe a Windows + Node.js thing. I just tried switching to a newer version of Node.js (16.9.0) and it didn't fix
Hmm, I can't figure it out. Very likely some weird Windows thing
When I try run a different command with a similar 'long' URL, it works, e.g.
node C:\Users\louis\Documents\Dev\Cloakist\cloakist-api\tools\check-from-email
I also tried adding quote marks around all URLs
When I try run only
node "C:\Users\louis\Documents\Dev\Cloakist\cloakist-sotion\node_modules\@serverless-stack\resources\assets\NextjsSite\build.js"
I get
throw new Error("--path parameter is required");
suggesting that this first path is found
When I run
node "C:\Users\louis\Documents\Dev\Cloakist\cloakist-sotion\node_modules\@serverless-stack\resources\assets\NextjsSite\build.js" --path "C:\Users\louis\Documents\Dev\Cloakist\cloakist-sotion\node_modules\cloakist-notion-nextjs" --config eyJjd2QiOiJDOlxcVXNlcnNcXGxvdWlzXFxEb2N1bWVudHNcXERldlxcQ2xvYWtpc3RcXGNsb2FraXN0LXNvdGlvblxcbm9kZV9tb2R1bGVzXFxjbG9ha2lzdC1ub3Rpb24tbmV4dGpzIiwiYXJncyI6WyJidWlsZCJdfQ==
I get
throw new Error("--output parameter is required");
, suggesting that the --path is also found. Although then when I run it with --output and without --path it asks for --path, so I think perhaps this is not interesting info