Comments (8)
@ubergeoff We have released 1.1.0
that supports serverless.ts but there is sitll a bug when using import
statements in the file itself. havent figured that out
from nx-plugins.
Side note: The solution should be backwards compatible, correct?
i.e. users/devs should have the choice to choose between the serverless.yml
file for the serverless.ts
file - are you happy with this..?
from nx-plugins.
sounds like awesomeness, would you like to open a pr? i can walk you through the code 🚀
from nx-plugins.
OK. Can do... whats the effort involved? (if you have to guess) ..?
from nx-plugins.
These are the two main places you need to fix
- Change all the configs to use
.ts
instead of.yaml
- rename the template file
- revisit the
spec.ts
and make sure it checks for.ts
instead of.yaml
- Make sure the
serverless.ts
has the right initial code so that when schematics are generated it works out of the box
Tips:
- use
yarn link
to do local testing - in
https://github.com/flowaccount/nx-plugins/blob/master/libs/nx-serverless/src/utils/serverless.ts
change import on the first line to be import * as Serverless from '/node_modules/serverless/lib/Serverless.js'; instead of 'serverless/lib/Serverless'; for local testing to work.
https://github.com/flowaccount/nx-plugins/blob/master/libs/nx-serverless/src/schematics/utils.ts#L18
https://github.com/flowaccount/nx-plugins/blob/master/libs/nx-serverless/src/schematics/api/files/serverless.yml.template
See whts comfortable :) we can review the code once its done :)
from nx-plugins.
++ Serverless has this code in it: (when reading the serverless config file)
case '.ts': {
if (!process[Symbol.for('ts-node.register.instance')]) {
const tsNodePath = await (async () => {
try {
return await resolveTsNode(path.dirname(configurationPath));
} catch (error) {
throw new ServerlessError(
`Cannot parse "${path.basename(
configurationPath
)}": Resolution of "ts-node" failed with: ${error.message}`,
'CONFIGURATION_RESOLUTION_ERROR'
);
}
})();
try {
require(tsNodePath).register();
} catch (error) {
throw new ServerlessError(
`Cannot parse "${path.basename(
configurationPath
)}": Register of "ts-node" failed with: ${error.message}`,
'CONFIGURATION_RESOLUTION_ERROR'
);
}
}
}
// fallthrough
case '.js': {
const configurationEventuallyDeferred = (() => {
try {
return require(configurationPath);
} catch (error) {
if (isModuleNotFoundError(error, configurationPath)) {
throw new ServerlessError(
`Cannot load 1 "${path.basename(configurationPath)}": File not found`,
'CONFIGURATION_NOT_FOUND'
);
}
console.log(error);
throw new ServerlessError(
`Cannot load 2 "${path.basename(configurationPath)}": Initialization error: ${
error && error.stack ? error.stack : error
}`,
'CONFIGURATION_INITIALIZATION_ERROR'
);
}
})();
try {
return await configurationEventuallyDeferred;
} catch (error) {
throw new ServerlessError(
`Cannot load "${path.basename(configurationPath)}": Initialization error: ${
error && error.stack ? error.stack : error
}`,
'CONFIGURATION_INITIALIZATION_ERROR'
);
}
}
However - it never seems to run to the .ts
path - it always lands up in the "fall through" .js
path... Any idea's why that might happen..?
The error I get is:
An unhandled exception occurred: Cannot load 2 "serverless.ts": Initialization error: C:\t2-online\t2\apps\myapi\serverless.ts:1
import { environment } from './environment';
^^^^^^
SyntaxError: Cannot use import statement outside a module
from nx-plugins.
Side note: The solution should be backwards compatible, correct?
i.e. users/devs should have the choice to choose between the
serverless.yml
file for theserverless.ts
file - are you happy with this..?
I agree, as for the .js
file i think its because the code is compiled into '.js' before the serverless commands are run? ... I am not sure when those switches
are executed if before webpack-compile it should be ok but i am suspecting its after... Do you have a branch i can jump into?
from nx-plugins.
any update on this?
from nx-plugins.
Related Issues (20)
- [BUG] Cannot create new api HOT 1
- [BUG] Cannot find module '@nrwl/workspace/src/utilities/run-webpack' HOT 1
- [BUG] Schematic "init" cannot resolve the factory. HOT 3
- [BUG] nx-serverless: Property 'port' does not match the schema. '7777' should be a 'number'. HOT 1
- [BUG] When using npm as packager, pacakgelist is not properly computed resulting in "*" for all package versions HOT 2
- [FEAT] Webpack stats.json support HOT 4
- [BUG] NX 13 and Webpack5 Support HOT 10
- Configuration error at 'useDotenv': should be equal to constant HOT 2
- [BUG] After creating monorepo blank workspace not able to create api HOT 3
- [FEAT] Nx-Serverless | option to exclude ALL dependencies from build HOT 1
- Cannot destructure property 'name' of 'node' as it is undefined. - @flowaccount/scully-plugin-angular-delay
- Support newer Serverless framework
- [BUG] Not able to run or build the freshly scaffolded project HOT 3
- [FEAT] Build functions individually HOT 9
- [BUG] Zip file resolution error when deploying a single artifact HOT 18
- [BUG] External dependencies are unavailable after deploying HOT 5
- [BUG] Cannot Include Json Schema in serverless.yml HOT 6
- [BUG] Runtime.ImportModuleError in every Lambda function after deploying new project HOT 2
- [BUG] Missing compat.ts for sls executor HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nx-plugins.